Commit 394dc70f authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #1137 from gevent/issue1136

Also monkey-patch threading._Event on Python 2. Fixes #1136
parents c4e2fdb8 24c9b94f
......@@ -10,6 +10,10 @@
- Use strongly typed watcher callbacks in the libuv CFFI extensions.
This prevents dozens of compiler warnings.
- On Python 2, when monkey-patching `threading.Event`, also
monkey-patch the underlying class, ``threading._Event``. Some code
may be type-checking for that. See :issue:`1136`.
1.3a2 (2018-03-06)
==================
......
......@@ -405,6 +405,11 @@ def patch_thread(threading=True, _threading_local=True, Event=True, logging=True
if Event:
from gevent.event import Event
patch_item(threading_mod, 'Event', Event)
# Python 2 had `Event` as a function returning
# the private class `_Event`. Some code may be relying
# on that.
if hasattr(threading_mod, '_Event'):
patch_item(threading_mod, '_Event', Event)
if existing_locks:
_patch_existing_locks(threading_mod)
......
......@@ -26,12 +26,15 @@ class TestMonkey(unittest.TestCase):
self.assertIs(thread.start_new_thread, gthread.start_new_thread)
self.assertIs(threading._start_new_thread, gthread.start_new_thread)
# Event patched by default
self.assertTrue(monkey.is_object_patched('threading', 'Event'))
if sys.version_info[0] == 2:
from gevent import threading as gthreading
from gevent.event import Event as GEvent
self.assertIs(threading._sleep, gthreading._sleep)
# Event patched by default
self.assertTrue(monkey.is_object_patched('threading', 'Event'))
self.assertTrue(monkey.is_object_patched('threading', '_Event'))
self.assertIs(threading._Event, GEvent)
def test_socket(self):
import socket
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment