The 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 block
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691