Skip to content

Commit

Permalink
Improve Python 3 compat: threading WIP
Browse files Browse the repository at this point in the history
Should fix GH eventlet#153 "py3: green.threading.local is not green"
  • Loading branch information
jstasiak committed Nov 2, 2014
1 parent 651a575 commit 6bcb1dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 11 additions & 1 deletion eventlet/green/thread.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,6 +13,16 @@
__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

Expand Down
13 changes: 9 additions & 4 deletions eventlet/green/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
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()


patcher.inject(
'threading',
globals(),
('thread', thread),
('thread' if six.PY2 else '_thread', thread),
('time', time))

del patcher
Expand Down

0 comments on commit 6bcb1dc

Please sign in to comment.