[New-bugs-announce] [issue34110] cPickle may raise AttributeError when loading concurrently in threads
Guoqiang Zhang
report at bugs.python.org
Fri Jul 13 14:40:08 EDT 2018
New submission from Guoqiang Zhang <sangongs at gmail.com>:
If two threads use cPickle to load objects simultaneously, one thread may raise an AttributeError. This problem is caused by the partially loaded module.
To reproduce, create a file 'foo.py':
import time
time.sleep(0.1)
class foo():
pass
Then in main.py:
import threading
import cPickle
threads = [threading.Thread(target=cPickle.loads, args=('cfoo\nfoo\np0\n.',)) for _ in range(2)]
[thread.start() for thread in threads]
[thread.join() for thread in threads]
Run main.py, there should be a crash:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
AttributeError: 'module' object has no attribute 'foo'
----------
components: Library (Lib)
messages: 321627
nosy: sangongs
priority: normal
severity: normal
status: open
title: cPickle may raise AttributeError when loading concurrently in threads
type: crash
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34110>
_______________________________________
More information about the New-bugs-announce
mailing list