threading: extend

This commit is contained in:
Thomas Farstrike
2025-05-19 14:44:28 +02:00
parent 005f1c0c37
commit 6c2793e935
+15 -5
View File
@@ -1,11 +1,21 @@
try:
import _thread
except ImportError:
_thread = None
import _thread
class Thread:
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None):
self.target = target
self.args = args
self.kwargs = {} if kwargs is None else kwargs
def start(self):
_thread.start_new_thread(self.run, ())
def run(self):
self.target(*self.args, **self.kwargs)
class Lock:
def __init__(self):
self._lock = _thread.allocate_lock() if _thread else None
self._lock = _thread.allocate_lock()
def __enter__(self):
if self._lock: