Skip to content Skip to sidebar Skip to footer

Exit A Process While Threads Are Sleeping

In a python script, I started a bunch of threads, each of which pulls some resource at an interval using time.sleep(interval). I have another thread running, which uses the cmd mod

Solution 1:

sys.exit will only stop the thread it executes from. If you have other non-daemon thread in your program they will continue to execute. Section 17.2.1 of the Python library docs contains:

A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program exits when only daemon threads are left. The initial value is inherited from the creating thread. The flag can be set through the daemon property.

See also Why does sys.exit() not exit when called inside a thread in Python?.

Post a Comment for "Exit A Process While Threads Are Sleeping"