[issue34110] cPickle may raise AttributeError when loading concurrently in threads

2018-07-13 Thread Guoqiang Zhang


New submission from Guoqiang Zhang :

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 
<https://bugs.python.org/issue34110>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34110] cPickle may raise AttributeError when loading concurrently in threads

2018-07-13 Thread Guoqiang Zhang


Change by Guoqiang Zhang :


--
keywords: +patch
pull_requests: +7812
stage:  -> patch review

___
Python tracker 
<https://bugs.python.org/issue34110>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com