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
Intermittent parse() KeyError failure with 2.8.0 #901
Comments
Hmmm, very interesting. I'm not quite sure which operation is not thread-safe, but from the stack trace I'm guessing it's In any case, I think we can fix it by switching this into two operations: cls.__strong_cache.setdefault(key, instance)
cls.__strong_cache.move_to_end(key, last=True) @kainjow Any way you might be able to put together a minimal reproducing script so that we can test that it's fixed? |
@kainjow By the way, what version of Python were you using? If this was a bug in OrderedDict that has been fixed, that would be good to know. Looks like it might be this bug in CPython. Not sure which versions are affected. |
We're on 2.7.13 (upgrade to 3.7 is in progress). |
OK, so I have written a little reproducer, it seems that import threading
from collections import OrderedDict
import sys
if sys.version_info[0] < 3:
from threading import Thread,Semaphore
class Barrier:
def __init__(self, n):
self.n = n
self.count = 0
self.mutex = Semaphore(1)
self.barrier = Semaphore(0)
def wait(self):
self.mutex.acquire()
self.count = self.count + 1
self.mutex.release()
if self.count == self.n: self.barrier.release()
self.barrier.acquire()
self.barrier.release()
else:
from threading import Barrier
d = OrderedDict(a=4)
N = 500
b = Barrier(N)
b2 = Barrier(N+1)
def popper():
b.wait()
d['a'] = d.pop('a', 4)
b2.wait()
for i in range(N):
threading.Thread(target=popper).start()
b2.wait()
print("Done") Maybe we can get the fix implemented in Python 2.7. In the meantime, while we still support Python 2, it might be a good idea to switch to the implementation in my earlier response, ideally with a note that we can switch it back when we drop Python 2. |
I am having this same issue in Python 2.7 and dateutil 2.7.5. |
Hi,
|
This rare parse() KeyError occurred for me running dateutil 2.8.1 on Python 2.7 (Google App Engine). It doesn't seem like this bug is fixed. |
We are seeing a KeyError exception with 2.8.0 intermittently. We have reverted to 2.7.5 for now. Seems like a thread safety issue with the new strong cache? Here's the traceback:
The text was updated successfully, but these errors were encountered: