This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cPickle may raise AttributeError when loading concurrently in threads
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: cheryl.sabella, pablogsal, pitrou, sangongs
Priority: normal Keywords: patch

Created on 2018-07-13 18:40 by sangongs, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8276 closed sangongs, 2018-07-13 18:57
Messages (4)
msg321627 - (view) Author: Guoqiang Zhang (sangongs) * Date: 2018-07-13 18:40
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'
msg321639 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2018-07-13 23:00
This behaviour also happens on the current master.
msg339750 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-04-09 13:51
Adding @pitrou to the nosy list as he last modified the section of code changed in the PR.
msg359723 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2020-01-10 12:37
Fixed in Python 3 with #34572.
History
Date User Action Args
2022-04-11 14:59:03adminsetgithub: 78291
2020-01-10 12:37:17cheryl.sabellasetstatus: open -> closed
versions: - Python 3.7, Python 3.8
messages: + msg359723

resolution: wont fix
stage: patch review -> resolved
2019-04-09 13:51:30cheryl.sabellasetnosy: + cheryl.sabella, pitrou

messages: + msg339750
versions: - Python 3.6
2018-07-13 23:00:16pablogsalsetversions: + Python 3.6, Python 3.7, Python 3.8
2018-07-13 23:00:00pablogsalsetnosy: + pablogsal
messages: + msg321639
2018-07-13 18:57:32sangongssetkeywords: + patch
stage: patch review
pull_requests: + pull_request7812
2018-07-13 18:40:08sangongscreate