Created
December 3, 2023 21:57
-
-
Save devsamuelv/7be4b836370b776a5c8e27e1bd66ebd2 to your computer and use it in GitHub Desktop.
A simple thread manager.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Thread | |
from threading import Thread | |
# A simple thread manager to control a single daemon at a time. | |
class Orchestrator: | |
def __init__(self) -> None: | |
self.current_thread = None | |
pass | |
def schedule(self, thread: Thread) -> bool: | |
if self.current_thread is not None: | |
return False | |
self.current_thread = thread | |
self.current_thread.daemon = True | |
self.current_thread.start() | |
return True | |
def get_current_thread(self) -> Thread: | |
return self.current_thread | |
def kill_thread(self): | |
self.current_thread._tstate_lock.release() | |
self.current_thread._stop() | |
self.current_thread = None | |
def thread_join(self): | |
self.current_thread.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment