diff options
| author | Jakub Stasiak <jakub@stasiak.at> | 2014-11-02 16:44:53 +0000 |
|---|---|---|
| committer | Jakub Stasiak <jakub@stasiak.at> | 2014-11-02 16:45:23 +0000 |
| commit | 6bcb1dc3686f72b0f1af803b46883ce4f5e4b8df (patch) | |
| tree | 1fac4642a37bc85e338fc10c184421476e455be7 | |
| parent | 651a575ba69ef2b1f882360c5c7ba3ad23783626 (diff) | |
| download | eventlet-python3.tar.gz | |
Improve Python 3 compat: threading WIPpython3
Should fix GH #153 "py3: green.threading.local is not green"
| -rw-r--r-- | eventlet/green/thread.py | 12 | ||||
| -rw-r--r-- | eventlet/green/threading.py | 13 |
2 files changed, 20 insertions, 5 deletions
diff --git a/eventlet/green/thread.py b/eventlet/green/thread.py index 66bb581..d2d492a 100644 --- a/eventlet/green/thread.py +++ b/eventlet/green/thread.py @@ -1,6 +1,6 @@ """Implements the standard thread module, using greenthreads.""" from eventlet.support.six.moves import _thread as __thread -from eventlet.support import greenlets as greenlet +from eventlet.support import greenlets as greenlet, six from eventlet import greenthread from eventlet.semaphore import Semaphore as LockType @@ -13,6 +13,16 @@ error = __thread.error __threadcount = 0 +if six.PY3: + def _set_sentinel(): + # HACK this is dummy code + # TODO possibly reimplement this: + # https://hg.python.org/cpython/file/b5e9bc4352e1/Modules/_threadmodule.c#l1203 + return allocate_lock() + + TIMEOUT_MAX = __thread.TIMEOUT_MAX + + def _count(): return __threadcount diff --git a/eventlet/green/threading.py b/eventlet/green/threading.py index 5c56ba1..3176261 100644 --- a/eventlet/green/threading.py +++ b/eventlet/green/threading.py @@ -2,12 +2,17 @@ from eventlet import patcher from eventlet.green import thread from eventlet.green import time -from eventlet.support import greenlets as greenlet +from eventlet.support import greenlets as greenlet, six -__patched__ = ['_start_new_thread', '_allocate_lock', '_get_ident', '_sleep', - 'local', 'stack_size', 'Lock', 'currentThread', +__patched__ = ['_start_new_thread', '_allocate_lock', + '_sleep', 'local', 'stack_size', 'Lock', 'currentThread', 'current_thread', '_after_fork', '_shutdown'] +if six.PY2: + __patched__ += ['_get_ident'] +else: + __patched__ += ['get_ident', '_set_sentinel'] + __orig_threading = patcher.original('threading') __threadlocal = __orig_threading.local() @@ -15,7 +20,7 @@ __threadlocal = __orig_threading.local() patcher.inject( 'threading', globals(), - ('thread', thread), + ('thread' if six.PY2 else '_thread', thread), ('time', time)) del patcher |
