"""Drop-in replacement for the thread module. Meant to be used as a brain-dead substitute so that threaded code does not need to be rewritten for when the thread module is not present. Suggested usage is:: try: import _thread except ImportError: import _dummy_thread as _thread """ # 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'] # A dummy value TIMEOUT_MAX = 2**31 # NOTE: this module can be imported early in the extension building process, # and so top level imports of other modules should be avoided. Instead, all # imports are done when needed on a function-by-function basis. Since threads # are disabled, the import lock should not be an issue anyway (??). error = RuntimeError def start_new_thread(function, args, kwargs={}): """Dummy implementation of _thread.start_new_thread(). Compatibility is maintained by making sure that ``args`` is a tuple and ``kwargs`` is a dictionary. If an exception is raised and it is SystemExit (which can be done by _thread.exit()) it is caught and nothing is done; all other exceptions are printed out by using traceback.print_exc(). If the executed function calls interrupt_main the KeyboardInterrupt will be raised when the function returns. """ if type(args) != type(tuple()): raise TypeError("2nd arg must be a tuple") if type(kwargs) != type(dict()): raise TypeError("3rd arg must be a dict") global _main _main = False try: function(*args, **kwargs) except SystemExit: pass except: import traceback traceback.print_exc() _main = True global _interrupt if _interrupt: _interrupt = False raise KeyboardInterrupt def exit(): """Dummy implementation of _thread.exit().""" raise SystemExit def get_ident(): """Dummy implementation of _thread.get_ident(). Since this module should only be used when _threadmodule is not available, it is safe to assume that the current process is the only thread. Thus a constant can be safely returned. """ return -1 def allocate_lock(): """Dummy implementation of _thread.allocate_lock().""" return LockType() def stack_size(size=None): """Dummy implementation of _thread.stack_size().""" if size is not None: raise error("setting thread stack size not supported") return 0 def _set_sentinel(): """Dummy implementation of _thread._set_sentinel().""" return LockType() class LockType(object): """Class implementing dummy implementation of _thread.LockType. Compatibility is maintained by maintaining self.locked_status which is a boolean that stores the state of the lock. Pickling of the lock, though, should not be done since if the _thread module is then used with an unpickled ``lock()`` from here problems could occur from this class not having atomic methods. """ def __init__(self): self.locked_status = False def acquire(self, waitflag=None, timeout=-1): """Dummy implementation of acquire(). For blocking calls, self.locked_status is automatically set to True and returned appropriately based on value of ``waitflag``. If it is non-blocking, then the value is actually checked and not set if it is already acquired. This is all done so that threading.Condition's assert statements aren't triggered and throw a little fit. """ if waitflag is None or waitflag: self.locked_status = True return True else: if not self.locked_status: self.locked_status = True return True else: if timeout > 0: import time time.sleep(timeout) return False __enter__ = acquire def __exit__(self, typ, val, tb): self.release() def release(self): """Release the dummy lock.""" # XXX Perhaps shouldn't actually bother to test? Could lead # to problems for complex, threaded code. if not self.locked_status: raise error self.locked_status = False return True def locked(self): return self.locked_status def __repr__(self): return "<%s %s.%s object at %s>" % ( "locked" if self.locked_status else "unlocked", self.__class__.__module__, self.__class__.__qualname__, hex(id(self)) ) # Used to signal that interrupt_main was called in a "thread" _interrupt = False # True when not executing in a "thread" _main = True def interrupt_main(): """Set _interrupt flag to True to have start_new_thread raise KeyboardInterrupt upon exiting.""" if _main: raise KeyboardInterrupt else: global _interrupt _interrupt = True
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
asyncio | Folder | 0755 |
|
|
collections | Folder | 0755 |
|
|
concurrent | Folder | 0755 |
|
|
config-3.5m | Folder | 0755 |
|
|
ctypes | Folder | 0755 |
|
|
curses | Folder | 0755 |
|
|
dbm | Folder | 0755 |
|
|
distutils | Folder | 0755 |
|
|
Folder | 0755 |
|
||
encodings | Folder | 0755 |
|
|
ensurepip | Folder | 0755 |
|
|
html | Folder | 0755 |
|
|
http | Folder | 0755 |
|
|
idlelib | Folder | 0755 |
|
|
importlib | Folder | 0755 |
|
|
json | Folder | 0755 |
|
|
lib-dynload | Folder | 0755 |
|
|
lib2to3 | Folder | 0755 |
|
|
logging | Folder | 0755 |
|
|
multiprocessing | Folder | 0755 |
|
|
plat-linux | Folder | 0755 |
|
|
pydoc_data | Folder | 0755 |
|
|
site-packages | Folder | 0755 |
|
|
sqlite3 | Folder | 0755 |
|
|
test | Folder | 0755 |
|
|
unittest | Folder | 0755 |
|
|
urllib | Folder | 0755 |
|
|
venv | Folder | 0755 |
|
|
wsgiref | Folder | 0755 |
|
|
xml | Folder | 0755 |
|
|
xmlrpc | Folder | 0755 |
|
|
__future__.py | File | 4.73 KB | 0644 |
|
__phello__.foo.py | File | 64 B | 0644 |
|
_bootlocale.py | File | 1.27 KB | 0644 |
|
_collections_abc.py | File | 24.21 KB | 0644 |
|
_compat_pickle.py | File | 8.36 KB | 0644 |
|
_compression.py | File | 5.21 KB | 0644 |
|
_dummy_thread.py | File | 5 KB | 0644 |
|
_markupbase.py | File | 14.26 KB | 0644 |
|
_osx_support.py | File | 18.67 KB | 0644 |
|
_pydecimal.py | File | 223.27 KB | 0644 |
|
_pyio.py | File | 85.91 KB | 0644 |
|
_sitebuiltins.py | File | 3.04 KB | 0644 |
|
_strptime.py | File | 21.67 KB | 0644 |
|
_sysconfigdata.py | File | 22.78 KB | 0644 |
|
_threading_local.py | File | 7.24 KB | 0644 |
|
_weakrefset.py | File | 5.57 KB | 0644 |
|
abc.py | File | 8.43 KB | 0644 |
|
aifc.py | File | 31.22 KB | 0644 |
|
antigravity.py | File | 476 B | 0644 |
|
argparse.py | File | 88.03 KB | 0644 |
|
ast.py | File | 11.72 KB | 0644 |
|
asynchat.py | File | 11.69 KB | 0644 |
|
asyncore.py | File | 19.63 KB | 0644 |
|
base64.py | File | 20.04 KB | 0755 |
|
bdb.py | File | 22.81 KB | 0644 |
|
binhex.py | File | 13.63 KB | 0644 |
|
bisect.py | File | 2.53 KB | 0644 |
|
bz2.py | File | 12.13 KB | 0644 |
|
cProfile.py | File | 5.2 KB | 0755 |
|
calendar.py | File | 22.46 KB | 0644 |
|
cgi.py | File | 35.2 KB | 0755 |
|
cgitb.py | File | 11.74 KB | 0644 |
|
chunk.py | File | 5.3 KB | 0644 |
|
cmd.py | File | 14.51 KB | 0644 |
|
code.py | File | 9.88 KB | 0644 |
|
codecs.py | File | 35.38 KB | 0644 |
|
codeop.py | File | 5.85 KB | 0644 |
|
colorsys.py | File | 3.97 KB | 0644 |
|
compileall.py | File | 11.44 KB | 0644 |
|
configparser.py | File | 52.2 KB | 0644 |
|
contextlib.py | File | 12.16 KB | 0644 |
|
copy.py | File | 8.74 KB | 0644 |
|
copyreg.py | File | 6.67 KB | 0644 |
|
crypt.py | File | 1.83 KB | 0644 |
|
csv.py | File | 15.75 KB | 0644 |
|
datetime.py | File | 74.12 KB | 0644 |
|
decimal.py | File | 320 B | 0644 |
|
difflib.py | File | 82.23 KB | 0644 |
|
dis.py | File | 16.94 KB | 0644 |
|
doctest.py | File | 101.6 KB | 0644 |
|
dummy_threading.py | File | 2.75 KB | 0644 |
|
enum.py | File | 21.71 KB | 0644 |
|
filecmp.py | File | 9.6 KB | 0644 |
|
fileinput.py | File | 13.92 KB | 0644 |
|
fnmatch.py | File | 3.09 KB | 0644 |
|
formatter.py | File | 14.79 KB | 0644 |
|
fractions.py | File | 24.04 KB | 0644 |
|
ftplib.py | File | 34.13 KB | 0644 |
|
functools.py | File | 28.27 KB | 0644 |
|
genericpath.py | File | 4.26 KB | 0644 |
|
getopt.py | File | 7.31 KB | 0644 |
|
getpass.py | File | 5.85 KB | 0644 |
|
gettext.py | File | 21.03 KB | 0644 |
|
glob.py | File | 4.95 KB | 0644 |
|
gzip.py | File | 19.79 KB | 0644 |
|
hashlib.py | File | 7.79 KB | 0644 |
|
heapq.py | File | 22.39 KB | 0644 |
|
hmac.py | File | 4.94 KB | 0644 |
|
imaplib.py | File | 50.96 KB | 0644 |
|
imghdr.py | File | 3.67 KB | 0644 |
|
imp.py | File | 10.43 KB | 0644 |
|
inspect.py | File | 111.52 KB | 0644 |
|
io.py | File | 3.32 KB | 0644 |
|
ipaddress.py | File | 73.96 KB | 0644 |
|
keyword.py | File | 2.17 KB | 0755 |
|
linecache.py | File | 5.19 KB | 0644 |
|
locale.py | File | 72.96 KB | 0644 |
|
lzma.py | File | 12.62 KB | 0644 |
|
macpath.py | File | 5.77 KB | 0644 |
|
macurl2path.py | File | 2.67 KB | 0644 |
|
mailbox.py | File | 76.58 KB | 0644 |
|
mailcap.py | File | 7.91 KB | 0644 |
|
mimetypes.py | File | 20.36 KB | 0644 |
|
modulefinder.py | File | 22.54 KB | 0644 |
|
netrc.py | File | 5.61 KB | 0644 |
|
nntplib.py | File | 42.07 KB | 0644 |
|
ntpath.py | File | 22.26 KB | 0644 |
|
nturl2path.py | File | 2.39 KB | 0644 |
|
numbers.py | File | 10 KB | 0644 |
|
opcode.py | File | 5.75 KB | 0644 |
|
operator.py | File | 10.61 KB | 0644 |
|
optparse.py | File | 58.93 KB | 0644 |
|
os.py | File | 36.17 KB | 0644 |
|
pathlib.py | File | 45.9 KB | 0644 |
|
pdb.py | File | 59.72 KB | 0755 |
|
pickle.py | File | 54.86 KB | 0644 |
|
pickletools.py | File | 89.61 KB | 0644 |
|
pipes.py | File | 8.71 KB | 0644 |
|
pkgutil.py | File | 20.85 KB | 0644 |
|
platform.py | File | 45.07 KB | 0755 |
|
plistlib.py | File | 31.06 KB | 0644 |
|
poplib.py | File | 14.37 KB | 0644 |
|
posixpath.py | File | 14.56 KB | 0644 |
|
pprint.py | File | 20.37 KB | 0644 |
|
profile.py | File | 21.52 KB | 0755 |
|
pstats.py | File | 25.94 KB | 0644 |
|
pty.py | File | 4.65 KB | 0644 |
|
py_compile.py | File | 7.01 KB | 0644 |
|
pyclbr.py | File | 13.25 KB | 0644 |
|
pydoc.py | File | 101.22 KB | 0755 |
|
queue.py | File | 8.57 KB | 0644 |
|
quopri.py | File | 7.09 KB | 0755 |
|
random.py | File | 25.84 KB | 0644 |
|
re.py | File | 15.14 KB | 0644 |
|
reprlib.py | File | 5.21 KB | 0644 |
|
rlcompleter.py | File | 6.16 KB | 0644 |
|
runpy.py | File | 11.68 KB | 0644 |
|
sched.py | File | 6.07 KB | 0644 |
|
selectors.py | File | 18.98 KB | 0644 |
|
shelve.py | File | 8.33 KB | 0644 |
|
shlex.py | File | 11.18 KB | 0644 |
|
shutil.py | File | 39.11 KB | 0644 |
|
signal.py | File | 2.07 KB | 0644 |
|
site.py | File | 21 KB | 0644 |
|
smtpd.py | File | 34.54 KB | 0755 |
|
smtplib.py | File | 42.61 KB | 0755 |
|
sndhdr.py | File | 6.27 KB | 0644 |
|
socket.py | File | 26.5 KB | 0644 |
|
socketserver.py | File | 24.09 KB | 0644 |
|
sre_compile.py | File | 17.98 KB | 0644 |
|
sre_constants.py | File | 6.66 KB | 0644 |
|
sre_parse.py | File | 34.29 KB | 0644 |
|
ssl.py | File | 41.36 KB | 0644 |
|
stat.py | File | 4.92 KB | 0644 |
|
statistics.py | File | 19.08 KB | 0644 |
|
string.py | File | 11.58 KB | 0644 |
|
stringprep.py | File | 12.61 KB | 0644 |
|
struct.py | File | 257 B | 0644 |
|
subprocess.py | File | 57.53 KB | 0644 |
|
sunau.py | File | 17.67 KB | 0644 |
|
symbol.py | File | 2.06 KB | 0755 |
|
symtable.py | File | 7.02 KB | 0644 |
|
sysconfig.py | File | 23.89 KB | 0644 |
|
tabnanny.py | File | 11.15 KB | 0755 |
|
tarfile.py | File | 90.89 KB | 0755 |
|
telnetlib.py | File | 22.48 KB | 0644 |
|
tempfile.py | File | 26.01 KB | 0644 |
|
textwrap.py | File | 19.1 KB | 0644 |
|
this.py | File | 1003 B | 0644 |
|
threading.py | File | 47.88 KB | 0644 |
|
timeit.py | File | 12.11 KB | 0755 |
|
token.py | File | 3 KB | 0644 |
|
tokenize.py | File | 27.14 KB | 0644 |
|
trace.py | File | 30.81 KB | 0755 |
|
traceback.py | File | 21.66 KB | 0644 |
|
tracemalloc.py | File | 15.27 KB | 0644 |
|
tty.py | File | 879 B | 0644 |
|
types.py | File | 8.59 KB | 0644 |
|
typing.py | File | 78.26 KB | 0644 |
|
uu.py | File | 6.61 KB | 0755 |
|
uuid.py | File | 22.72 KB | 0644 |
|
warnings.py | File | 15.48 KB | 0644 |
|
wave.py | File | 17.27 KB | 0644 |
|
weakref.py | File | 19.99 KB | 0644 |
|
webbrowser.py | File | 21.32 KB | 0755 |
|
xdrlib.py | File | 5.77 KB | 0644 |
|
zipapp.py | File | 6.99 KB | 0644 |
|
zipfile.py | File | 71.95 KB | 0644 |
|