mirror of
https://github.com/python/cpython.git
synced 2025-07-31 23:23:11 +00:00
- prefer "import ... as" to "import / (assignments) / del" for most things
- when the thread module isn't available, subsequent attempts to import threading should not suceed
This commit is contained in:
parent
f05aa10eae
commit
a872595f31
1 changed files with 11 additions and 18 deletions
|
@ -1,34 +1,27 @@
|
||||||
"""Thread module emulating a subset of Java's threading model."""
|
"""Thread module emulating a subset of Java's threading model."""
|
||||||
|
|
||||||
import sys
|
import sys as _sys
|
||||||
import time
|
|
||||||
import thread
|
try:
|
||||||
import traceback
|
import thread
|
||||||
import StringIO
|
except ImportError:
|
||||||
|
del _sys.modules[__name__]
|
||||||
|
raise
|
||||||
|
|
||||||
|
from StringIO import StringIO as _StringIO
|
||||||
|
from time import time as _time, sleep as _sleep
|
||||||
|
from traceback import print_exc as _print_exc
|
||||||
|
|
||||||
# Rename some stuff so "from threading import *" is safe
|
# Rename some stuff so "from threading import *" is safe
|
||||||
__all__ = ['activeCount', 'Condition', 'currentThread', 'enumerate', 'Event',
|
__all__ = ['activeCount', 'Condition', 'currentThread', 'enumerate', 'Event',
|
||||||
'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread', 'Timer']
|
'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Thread', 'Timer']
|
||||||
|
|
||||||
_sys = sys
|
|
||||||
del sys
|
|
||||||
|
|
||||||
_time = time.time
|
|
||||||
_sleep = time.sleep
|
|
||||||
del time
|
|
||||||
|
|
||||||
_start_new_thread = thread.start_new_thread
|
_start_new_thread = thread.start_new_thread
|
||||||
_allocate_lock = thread.allocate_lock
|
_allocate_lock = thread.allocate_lock
|
||||||
_get_ident = thread.get_ident
|
_get_ident = thread.get_ident
|
||||||
ThreadError = thread.error
|
ThreadError = thread.error
|
||||||
del thread
|
del thread
|
||||||
|
|
||||||
_print_exc = traceback.print_exc
|
|
||||||
del traceback
|
|
||||||
|
|
||||||
_StringIO = StringIO.StringIO
|
|
||||||
del StringIO
|
|
||||||
|
|
||||||
|
|
||||||
# Debug support (adapted from ihooks.py)
|
# Debug support (adapted from ihooks.py)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue