You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Potential deadlock in concurrent futures when garbage collection occurs during Queue.get #65208
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2018-01-17.22:03:30.250>created_at=<Date2014-03-21.15:47:26.814>labels= ['type-bug', 'library']
title='Potential deadlock in concurrent futures when garbage collection occurs during Queue.get'updated_at=<Date2018-04-10.05:47:26.678>user='https://bugs.python.org/simonjagoe'
At Enthought we have been tracking a deadlock in some code that turned out to be due to the following scenario:
There is some cyclic garbage that requires collection; an object in the garbage is referred to by a weakref with a callback
You have a lock that is acquired
While the lock is held, the garbage collector runs (on the same thread)
The weakref callback in (0) is called via the garbage collecter and the callback tries to acquire the same lock that was acquired in (1)
Attached is a simple script that exercises the issue in Python 3.3. The script monkey-patches Queue.get to force garbage collection after acquiring the Queue.not_empty lock.
Davin: I don't see the link with bpo-14976. There are no external signals involved in this issue. There's just a piece of simple pure Python code, which can deadlock if gc happens to kick in at the wrong moment.
I don't really understand this issue. How is concurrent.futures supposed to be the culprit here? Can you elaborate which weakref callback you are talking about?
simonjagoe commented on Sep 10, 2017
simonjagoemannequin
MannequinAuthor
More actions
In the script attached to the original issue, the weakref callback that causes the hang is the callback defined in ThreadPoolExecutor._adjust_thread_count
Attached is a faulthandler stack captured from Python 3.6.1. The script submitted here uses a patched queue.get() method to force garbage collection to reliably trigger the issue, but this deadlock was observed in a real application using threadpool executors.
There's a proposed fix in #5216
It would be nice if someone able to reproduce this issue could test it (the reproducer script here wouldn't work with the new SimpleQueue implementation).
Activity
simonjagoe commentedon Mar 21, 2014
At Enthought we have been tracking a deadlock in some code that turned out to be due to the following scenario:
Attached is a simple script that exercises the issue in Python 3.3. The script monkey-patches Queue.get to force garbage collection after acquiring the Queue.not_empty lock.
mdickinson commentedon Apr 12, 2014
Adding Brian Quinlan to the nosy list.
I don't see an easy way around this other than documenting it and recommending that people do explicit executor shutdown where necessary.
Weakref callbacks are dangerous things. Weakref callbacks that acquire a lock at any point doubly so.
PatrikDufresne commentedon Sep 6, 2016
I've encounter this issue. To easily avoid this issue, I've change
queue.put(None)toqueue.put(None, block=False)to work around this.applio commentedon Sep 9, 2016
Sounds related to bpo-14976.
applio commentedon Sep 9, 2016
Per the decision of bpo-14976.
mdickinson commentedon Sep 9, 2016
Davin: I don't see the link with bpo-14976. There are no external signals involved in this issue. There's just a piece of simple pure Python code, which can deadlock if gc happens to kick in at the wrong moment.
I don't think this issue should be closed.
pitrou commentedon Sep 2, 2017
I don't really understand this issue. How is concurrent.futures supposed to be the culprit here? Can you elaborate which weakref callback you are talking about?
simonjagoe commentedon Sep 10, 2017
In the script attached to the original issue, the weakref callback that causes the hang is the callback defined in ThreadPoolExecutor._adjust_thread_count
Attached is a faulthandler stack captured from Python 3.6.1. The script submitted here uses a patched queue.get() method to force garbage collection to reliably trigger the issue, but this deadlock was observed in a real application using threadpool executors.
gpshead commentedon Jan 17, 2018
there's a PR on the other issue i opened for this without noticing this one so i'm marking this as the dup.
pitrou commentedon Jan 17, 2018
There's a proposed fix in #5216
It would be nice if someone able to reproduce this issue could test it (the reproducer script here wouldn't work with the new SimpleQueue implementation).