I made a simple ThreadManager class that receives tasks and spawns threads to complete the tasks. Currently it keeps all the threads alive until I explicitly set threadmgr.waiting=False and all of the tasks are complete. I'm trying to eliminate the need for the former. What I would prefer is that when the frame that instantiates the threadmgr terminates it automatically tells the threadmgr to stop waiting for new tasks. I've been looking at the inspect module and am able to get a line number that the parent frame is on but I don't see an easy way to determine if that frame has completed... It's probably a fairly simple solution. Thanks in advance.
ihatehippies
11
Junior Poster
Recommended Answers
Jump to PostThe normal solution is to use a 'with' statement
from contextlib import contextmanager @contextmanager def threadmgr_running(*args, **kwd): threadmgr = ThreadManager(*args, **kwd) threadmgr.start() # or whatever try: yield threadmgr finally: threadmgr.waiting = False # in code with threadmgr_running(...) as threadmgr: etc # the threadmgr terminates automatically after this …
All 2 Replies
Gribouillis
1,391
Programming Explorer
Team Colleague
JoshuaBurleson
commented:
for the props you deserve but didn't get
+3
ihatehippies
11
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.