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: Namedtuple instances can't be pickled in a daemonized process
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Claudiu.Popa, alexandre.vassalotti, eric.araujo, pitrou, rhettinger
Priority: normal Keywords:

Created on 2011-12-06 12:28 by Claudiu.Popa, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
daemon.py Claudiu.Popa, 2011-12-06 12:28
Messages (3)
msg148912 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2011-12-06 12:28
On Unix world, in a daemonized process, any namedtuple instance can't be pickled, failing with error:
_pickle.PicklingError: Can't pickle class X: attribute lookup __main__.t failed.
This can't be reproduced with the attached code. If I add the created class inside the globals dict, the pickling will work.
msg148913 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-12-06 12:35
As far as I can tell, this has nothing to do with daemon processes and all to do with the fact that user-defined classes have to be globally visible for their instances to be pickled. It is because pickles reference classes by name, and local names obviously don't work for that.

In other words, this is not a bug.
msg149162 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-12-10 15:57
Confirmed (3.2):

>>> def func():
...     t = collections.namedtuple('t', 'a')
...     instance = t(1)
...     print(instance)
...     return pickle.dumps(instance)

>>> func()
t(a=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 5, in func
_pickle.PicklingError: Can't pickle <class '__main__.t'>: attribute lookup __main__.t failed

We may open an enhancement request to suggest that the error message include the qualname, but otherwise this is not a bug.
History
Date User Action Args
2022-04-11 14:57:24adminsetgithub: 57746
2011-12-10 15:57:47eric.araujosetstatus: pending -> closed

nosy: + eric.araujo
messages: + msg149162

stage: resolved
2011-12-06 12:35:38pitrousetstatus: open -> pending
versions: - Python 3.4
nosy: + alexandre.vassalotti, pitrou

messages: + msg148913

resolution: not a bug
2011-12-06 12:28:22Claudiu.Popacreate