I am relatively new to programming, and what I am asking might be a task that is not possible. What I want to do is start a parallel process, which will continuously run until
Use a queue. (python 2 is Queue
)
There are a few ways to consume from the queue. The naive implementation (i.e. the one that has a race condition) is simply to do if q.empty()
. This is bad practice but wouldn't hurt you since it's not mission critical if you miss a tick.
The better method is to use exceptions for flow control:
q = queue.Queue()
try:
q.get(False) #non-blocking get()
#update value of i, etc
except queue.Empty:
#do stuff here as before