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

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

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -