You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
threading: extend
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user