Skip to content

Instantly share code, notes, and snippets.

@devsamuelv
Created December 3, 2023 21:57
Show Gist options
  • Save devsamuelv/7be4b836370b776a5c8e27e1bd66ebd2 to your computer and use it in GitHub Desktop.
Save devsamuelv/7be4b836370b776a5c8e27e1bd66ebd2 to your computer and use it in GitHub Desktop.
A simple thread manager.
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