diff --git a/Lib/_dummy_thread.py b/Lib/_dummy_thread.py index 36e5f38ae..293669f35 100644 --- a/Lib/_dummy_thread.py +++ b/Lib/_dummy_thread.py @@ -14,7 +14,7 @@ Suggested usage is:: # Exports only things specified by thread documentation; # skipping obsolete synonyms allocate(), start_new(), exit_thread(). __all__ = ['error', 'start_new_thread', 'exit', 'get_ident', 'allocate_lock', - 'interrupt_main', 'LockType'] + 'interrupt_main', 'LockType', 'RLock'] # A dummy value TIMEOUT_MAX = 2**31 @@ -161,3 +161,35 @@ def interrupt_main(): else: global _interrupt _interrupt = True + +class RLock: + def __init__(self): + self.locked_count = 0 + + def acquire(self, waitflag=None, timeout=-1): + self.locked_count += 1 + return True + + __enter__ = acquire + + def __exit__(self, typ, val, tb): + self.release() + + def release(self): + if not self.locked_count: + raise error + self.locked_count -= 1 + return True + + def locked(self): + return self.locked_status != 0 + + def __repr__(self): + return "<%s %s.%s object owner=%s count=%s at %s>" % ( + "locked" if self.locked_count else "unlocked", + self.__class__.__module__, + self.__class__.__qualname__, + get_ident() if self.locked_count else 0, + self.locked_count, + hex(id(self)) + ) diff --git a/Lib/functools.py b/Lib/functools.py index 4cde5f590..59298455d 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -18,7 +18,10 @@ from abc import get_cache_token from collections import namedtuple # import types, weakref # Deferred to single_dispatch() from reprlib import recursive_repr -from _thread import RLock +try: + from _thread import RLock +except ModuleNotFoundError: + from _dummy_thread import RLock ################################################################################ diff --git a/Lib/reprlib.py b/Lib/reprlib.py index 616b3439b..6b0283b79 100644 --- a/Lib/reprlib.py +++ b/Lib/reprlib.py @@ -4,7 +4,10 @@ __all__ = ["Repr", "repr", "recursive_repr"] import builtins from itertools import islice -from _thread import get_ident +try: + from _thread import get_ident +except ModuleNotFoundError: + from _dummy_thread import get_ident def recursive_repr(fillvalue='...'): 'Decorator to make a repr function return fillvalue for a recursive call' diff --git a/wasm/demo/src/index.js b/wasm/demo/src/index.js index 9e03edb61..150fab739 100644 --- a/wasm/demo/src/index.js +++ b/wasm/demo/src/index.js @@ -148,7 +148,7 @@ function onReady() { runCodeFromTextarea(); terminalVM = rp.vmStore.init('term_vm'); - terminalVM.setStdout(data => localEcho.println(data)); + terminalVM.setStdout(data => localEcho.print(data)); readPrompts().catch(err => console.error(err)); // so that the test knows that we're ready