Skip to content

Named tuples in psutil._common not picklable #461

Closed
@giampaolo

Description

From countac...@gmail.com on December 29, 2013 20:26:39

What steps will reproduce the problem?  
1. Call psutil function that returns named tuple (e.g. psutil.disk_partitions())
2. Try to call pickle.dumps on returned value 

What is the expected output?  
Should return pickle serialized version of named tuple. 

What do you see instead?  
Throws pickle error. This is because the namedtuple variables are not named the 
same as the namedtuples themselves. For example:

nt_sysmeminfo = namedtuple('usage', 'total used free percent')

Pickle attempts to find the type that the namedtuple object is derived from via 
the psutil._common.usage variable, which does not exist (since it is instead 
located at psutil._common.nt_sysmeminfo). The problem can be corrected simply 
by changing the above line to:

nt_sysmeminfo = namedtuple('nt_sysmeminfo', 'total used free percent') 

What version of psutil are you using? What Python version?  
Python 2.7.6, psutil 1.2.1 

On what operating system? Is it 32bit or 64bit version?  
Debian Jessie, 64-bit 

Please provide any additional information below.  
See above ^^^

Original issue: http://code.google.com/p/psutil/issues/detail?id=461

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions