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: Error in pickle using cProfile
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: trace/profile conflict with the use of sys.modules[__name__]
View: 9914
Assigned To: Nosy List: Erick Fonseca, georg.brandl, serhiy.storchaka
Priority: normal Keywords:

Created on 2015-07-20 22:23 by Erick Fonseca, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg247006 - (view) Author: Erick Fonseca (Erick Fonseca) Date: 2015-07-20 22:23
cPickle raises a PicklingError when trying to pickle an instance of a class defined in a module being profiled with cProfile.

Example code:

    import cPickle

    class A(object):
        pass

    a = A()
    with open('file.dat', 'wb') as f:
        cPickle.dump(a, f)

Running the above example with python -m cProfile resulted in 

cPickle.PicklingError: Can't pickle <class '__main__.A'>: attribute lookup __main__.A failed

I'm not sure if this is the intended behavior (I suppose __main__ in this case refers to the cProfile module file), but I googled it and couldn't find anything. I noticed this problem in Ubuntu 14.04 and Windows 8.1, both with Python 2.7.
msg247010 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-07-21 02:53
The same is with profile, pickle and in 3.x. May be profile should set sys.modules['__main__']?
msg247013 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-07-21 05:52
This looks as duplicate of issue9914.
History
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 68864
2015-07-21 05:52:20serhiy.storchakasetstatus: open -> closed
superseder: trace/profile conflict with the use of sys.modules[__name__]
resolution: duplicate
messages: + msg247013
2015-07-21 02:53:31serhiy.storchakasetversions: + Python 3.4, Python 3.5, Python 3.6
nosy: + georg.brandl, serhiy.storchaka

messages: + msg247010

components: + Library (Lib), - Extension Modules
type: crash -> behavior
2015-07-20 22:23:56Erick Fonsecacreate