mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
python: allow usage of communicate() without blocking
This commit is contained in:
parent
92a2f2cfbf
commit
f0bcf744e9
1 changed files with 7 additions and 6 deletions
|
@ -60,7 +60,7 @@ class SendThread(Thread):
|
||||||
self.sequence += 1
|
self.sequence += 1
|
||||||
|
|
||||||
|
|
||||||
def communicate(rate, recv_cb=None, send_cb=None):
|
def communicate(rate, recv_cb=None, send_cb=None, wait=True):
|
||||||
|
|
||||||
if recv_cb:
|
if recv_cb:
|
||||||
rt = RecvThread(recv_cb)
|
rt = RecvThread(recv_cb)
|
||||||
|
@ -70,11 +70,12 @@ def communicate(rate, recv_cb=None, send_cb=None):
|
||||||
st = SendThread(send_cb, rate)
|
st = SendThread(send_cb, rate)
|
||||||
st.start()
|
st.start()
|
||||||
|
|
||||||
try:
|
if wait:
|
||||||
while True:
|
try:
|
||||||
time.sleep(1)
|
while True:
|
||||||
except KeyboardInterrupt:
|
time.sleep(1)
|
||||||
logger.info('Received Ctrl+C. Stopping send/recv threads')
|
except KeyboardInterrupt:
|
||||||
|
logger.info('Received Ctrl+C. Stopping send/recv threads')
|
||||||
|
|
||||||
# Threads are daemon threads
|
# Threads are daemon threads
|
||||||
# and therefore killed with program termination
|
# and therefore killed with program termination
|
Loading…
Add table
Reference in a new issue