Merge pull request #1982 from RustPython/coolreader18/wasm-_thread

Fix issues with wasm code missing _thread
This commit is contained in:
Noah authored and GitHub committed 2020-07-11 08:20:27 -05:00
commit 9fa294e958
4 files changed
+42 -4

No files matched your search

+33 -1
View File
@@ -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))
)
+4 -1
View File
@@ -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
################################################################################
+4 -1
View File
@@ -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'
+1 -1
View File
@@ -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