Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

threading.RLock (and threading.Condition) doesn't work on Python 3.2+ with monkey-patching #185

Closed
vstinner opened this issue Jan 5, 2015 · 1 comment

Comments

@vstinner
Copy link
Contributor

vstinner commented Jan 5, 2015

The threading.RLock class was reimplemented in C in Python 3.2. threading.RLock doesn't use _thread.get_ident() or threading.get_ident(), but it calls directly the C function. Because of that, RLock doesn't work ("as expected") with eventlet monkey-patching. Example:

#!python
import eventlet
eventlet.monkey_patch()

import threading
#threading.RLock = threading._PyRLock

def func(c):
    with c:
        print("thread: owned?", c._is_owned())
        c.notify()
        print("thread: owned?", c._is_owned())

c = threading.Condition()
print("LOCK", threading.RLock)
with c:
    t = threading.Thread(target=func, args=(c,))
    t.start()
    print("main: owned?", c._is_owned())
    c.wait()
    print("main: owned?", c._is_owned())

The code hangs with eventlet 0.16 on Python 3.5 (and probably also Python 3.2, 3.3 and 3.4).

I tried to reuse the Python implementation of the RLock class (threading._PyRLock), but in this case c.notify() raises: RuntimeError("cannot notify on un-acquired lock").

I will work on a fix.

Note: I'm working on porting the Oslo Messaging project to Python 3. The initial issue came from a threading.Condition object, threading.Condition uses internally a threading.RLock.

openstack-gerrit pushed a commit to openstack/oslo.messaging that referenced this issue Jan 21, 2015
With eventlet 0.16, it becomes possible to run Oslo Messaging tests on
Python 3 with eventlet.

This change ports the zmq driver to Python 3:

* encode the topic explicitly to UTF-8
* use a list comprehension instead of map() to also get a list
  on Python 3 (not a generator)

The following eventlet change is needed to run tests:
eventlet/eventlet#187

Related eventlet issue:
eventlet/eventlet#185

I will propose a different change to enable tests with eventlet enabled
when a release of eventlet including this fix will be available.

Change-Id: Ic8fec515cfa757e08ffb9604e3bfb2e87d08f3d8
openstack-gerrit pushed a commit to openstack/openstack that referenced this issue Jan 21, 2015
Project: openstack/oslo.messaging  ae009a4ed99caa414104bc06829ac5a4f4cc9d2c

Port zmq driver to Python 3

With eventlet 0.16, it becomes possible to run Oslo Messaging tests on
Python 3 with eventlet.

This change ports the zmq driver to Python 3:

* encode the topic explicitly to UTF-8
* use a list comprehension instead of map() to also get a list
  on Python 3 (not a generator)

The following eventlet change is needed to run tests:
eventlet/eventlet#187

Related eventlet issue:
eventlet/eventlet#185

I will propose a different change to enable tests with eventlet enabled
when a release of eventlet including this fix will be available.

Change-Id: Ic8fec515cfa757e08ffb9604e3bfb2e87d08f3d8
openstack-gerrit pushed a commit to openstack/openstack that referenced this issue Jan 21, 2015
Project: openstack/oslo.messaging  ae009a4ed99caa414104bc06829ac5a4f4cc9d2c

Port zmq driver to Python 3

With eventlet 0.16, it becomes possible to run Oslo Messaging tests on
Python 3 with eventlet.

This change ports the zmq driver to Python 3:

* encode the topic explicitly to UTF-8
* use a list comprehension instead of map() to also get a list
  on Python 3 (not a generator)

The following eventlet change is needed to run tests:
eventlet/eventlet#187

Related eventlet issue:
eventlet/eventlet#185

I will propose a different change to enable tests with eventlet enabled
when a release of eventlet including this fix will be available.

Change-Id: Ic8fec515cfa757e08ffb9604e3bfb2e87d08f3d8
temoto pushed a commit that referenced this issue Mar 5, 2015
For the Python implementation of threading.RLock because the new C
implementation of threading.RLock of Python 3.3 is not compatible with
eventlet monkey patching.

Fix the issue #185.
temoto pushed a commit that referenced this issue Apr 5, 2015
For the Python implementation of threading.RLock because the new C
implementation of threading.RLock of Python 3.3 is not compatible with
eventlet monkey patching.

Fix the issue #185.
temoto pushed a commit that referenced this issue Apr 5, 2015
For the Python implementation of threading.RLock because the new C
implementation of threading.RLock of Python 3.3 is not compatible with
eventlet monkey patching.

Fix the issue #185.
@vstinner
Copy link
Contributor Author

vstinner commented Dec 5, 2016

Oslo Messaging now works well on Python 3 with eventlet. I don't recall how the issue was fixed, but it now works well :-) So I close this old issue.

@vstinner vstinner closed this as completed Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant