stoppable and restartable thread simply using an event
from sine.threads import * def func(stop_event): while 1: if stop_event.is_set(): break # do your work thread = StoppableThread(target=func) thread.start() # ... thread.stop(-1) # stop and join forever # thread.stopped() == True thread = ReStartableThread(target=func, event_name='stop_event') # can specify the parameter's name thread.start() # ... thread.stop(1) # stop and join for 1 second # ... thread.start() # ... thread.stop() thread.join() # ...
- change to run with python3
- stop() become stop(timeout=0) to join the thread for convenience and return whether it is alive.
- when the event_name is not specified, it is not strict to receive
the stop event any more, and it will be added to 'args'
so it can be receive by
*args'or other argument
- add: thread lock
- fix logic about join(), when directly join() without start() but stop()
- ReStartableThread support join the old thread instance
- fix: ReStartableThread.start always creates new instance
- improve comment and change to English
- change directory structure and update setup.py
- add tests.py
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size sine.threads-0.1.7.tar.gz (6.6 kB)||File type Source||Python version None||Upload date||Hashes View hashes|