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

Infinite recursion with __getattr__ when pickling/unpickling StreamWrapper (Python 2.7) #86

Closed
robahlgren opened this issue Feb 23, 2016 · 0 comments · Fixed by #339
Closed
Labels

Comments

@robahlgren
Copy link

The following error is repeated when attempting to unpickle (using dill) an object with a sys.stdout reference. (for example, spawning a process with a reference to a logger.)

>>> import dill
>>> from colorama.ansitowin32 import StreamWrapper
>>> dill.loads(dill.dumps(StreamWrapper(None, None)))

File "C:\...\lib\site-packages\colorama\ansitowin32.py", line 33, in __getattr__
  return getattr(self.__wrapped, name)
File "C:\...\lib\site-packages\colorama\ansitowin32.py", line 33, in __getattr__
  return getattr(self.__wrapped, name)
File "C:\...\lib\site-packages\colorama\ansitowin32.py", line 33, in __getattr__
  return getattr(self.__wrapped, name)
RuntimeError: maximum recursion depth exceeded

It appears simply adding setstate and getstate to StreamWrapper fixes the issue:

def __setstate__(self, state):
    self.__dict__ = state

def __getstate__(self):
    return self.__dict__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants