While loops and duplicate code in python -


i have tiny section in code check active threads non-daemon , non-main. these threads needs closed eventually, part check them duplicated follows:

threads = [th th in threading.enumerate()             if th not threading.main_thread() or not th.isdaemon()] while threads:     threads = [th th in threading.enumerate()                 if th not threading.main_thread() or not th.isdaemon()]     time.sleep(5) exit() 

i can try creating variable named count , check same function threading.active_count(). try avoid making count variable whenever can. indeed better code duplication. there other, more elegant, ways this?

threads = [th th in threading.enumerate()             if th not threading.main_thread() or not th.isdaemon()] while threads:     # pseudocode:     kill threads.pop()     time.sleep(5) exit() 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -