Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pickling error on enum #49

Closed
marzious opened this issue Nov 14, 2018 · 1 comment
Closed

Pickling error on enum #49

marzious opened this issue Nov 14, 2018 · 1 comment

Comments

@marzious
Copy link

Hi, I am replacing the multiprocessing with multiprocess module, and while my target function consist enum, it return pickling error. If the enum is removed, the function will run without issue.

My target function is a simple loop as I tried to troubleshoot the source of can't pickling:
def ExecuteMultiprocess(self):
list = []
i = States.DetectingShots
count = 0
while i is States.DetectingShots:
list.append(i)
print(i)
count = count+1
if count > 10:
break

Error
Traceback (most recent call last):
File "", line 1, in
File "C:\Gk\Pf\Gk\source\XShot\XShot\env\lib\site-packages\multiprocess\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Gk\Pf\Gk\source\XShot\XShot\env\lib\site-packages\multiprocess\spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
File "C:\Gk\Pf\Gk\source\XShot\XShot\env\lib\site-packages\dill_dill.py", line 304, in load
obj = pik.load()
EOFError: Ran out of input

@mmckerns
Copy link
Member

mmckerns commented May 3, 2019

Sorry for the slow response. I don't see where an Enum is used in your code. Did you mean from enum import Enum? The issue is indeed that enum.Enum is not serializable, unless you pickle it by reference. Within dill, you can change the pickle settings, so you get different variety of serialization. dill.settings['byref'] = True is very similar to pickle, and toggles on serialization by reference for classes. If you don't use this setting, dill throws an error:

Python 2.7.16 (default, Apr  1 2019, 14:50:56) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import dill  
>>> import enum
>>> 
>>> class Color(enum.Enum):
...   RED = 1
...   GREEN = 2
... 
>>> e = Color(1)
>>> dill.settings 
{'ignore': False, 'recurse': False, 'byref': False, 'protocol': 2, 'fmode': 0}
>>> dill.settings['byref'] = True
>>> dill.dumps(e)
'\x80\x02c__main__\nColor\nq\x00K\x01\x85q\x01Rq\x02.'
>>> dill.loads(_)
<Color.RED: 1>
>>> 
>>> dill.settings['byref']=False
>>> dill.dumps(e)
Traceback (most recent call last):
...
RecursionError: maximum recursion depth exceeded

This is the same regardless of version of python.

This seems to be either a duplicate issue of #48 (i.e. the dill settings can't be changed within multiprocessing), or an issue that belongs to dill uqfoundation/dill#250 (i.e. can't pickle an Enum).

So, I'm going to close this ticket as a duplicate. Please feel free to reopen and add further information or comments, if you have any.

@mmckerns mmckerns closed this as completed May 3, 2019
@mmckerns mmckerns added this to the multiprocess-0.70.8 milestone Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants