Python: How do I poll the time run by each child thread to the parent thread? So that after specific time frame I can invoke a new thread.
Asked
Active
Viewed 46 times
1 Answers
1
The standard way to communicate between parallel processes (such as threads) is a queue.
Each thread can remember the (wall clock) time of its own start. When it finishes, it can measure its run duration and post it to the queue. It can also post a progress message periodically (e.g. once it completes fetching an URL from a list), also with a timestamp and a duration.
The main thread can periodically poll the queue and see how other threads are doing.

9000
- 39,899
- 9
- 66
- 104
-
Thanks for the help. Could you show a block of code of how the main thread can poll the queue periodically to know about the status of the threads? – Naani48 Jul 19 '14 at 00:51
-
I suppose it will be a loop that checks `Queue.empty()`, does a [`Queue.get`](https://docs.python.org/2/library/queue.html#Queue.Queue.get) with a reasonably small timeout, and possibly some `time.sleep()` in between. See [some examples](http://stackoverflow.com/questions/2846653/). – 9000 Jul 19 '14 at 02:59