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

#$save macro does not work in many cases #53

Open
Almenon opened this issue Apr 21, 2018 · 2 comments
Open

#$save macro does not work in many cases #53

Almenon opened this issue Apr 21, 2018 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Almenon
Copy link
Owner

Almenon commented Apr 21, 2018

Currently I use deepcopy to save the state: https://docs.python.org/3.6/library/copy.html#copy.deepcopy

This means the types must be serializable by deepcopy, which unfortunately has some major limitations:

  • Deepcopy cannot handle the following types:

"This module does not copy types like module, method, stack trace, stack frame, file, socket, window, array, or any similar types"

  • Imports are not saved (although you can still use imports in the saved section, the import will just happen twice)

  • Conditional imports and imports in functions may not work

  • File I/O does not work (TextIOWrapper is not serializable)

Please comment below if you run into any issues with #$save

@Almenon Almenon added the bug Something isn't working label Apr 21, 2018
@Almenon
Copy link
Owner Author

Almenon commented May 26, 2018

another example in which save fails:

from urllib.request import urlopen
import json

data = urlopen("https://api.github.com/")

#$save
# error result: TypeError: cannot serialize '_io.BufferedReader' object 

@Almenon
Copy link
Owner Author

Almenon commented May 26, 2018

Ideas to fix problem:

A. define deepcopy() method on the uncopyable object to make it copyable. downside: who knows what object the user will be using? This solution would have to be manually implemented for certain types

B. Use deepcopy differently. Maybe there's some sort of argument I can pass in? Answer: no

C. Define my own deepcopy. See links 1, 2, and 3. Also the source code for the deepcopy

D. use copyreg?

E. freeze the thread and fork the process from the save point. This has the great benefit of me not having to worry about the users variables at all.

Some guy w/ similar problem: pyinvoke/invoke#421

@Almenon Almenon added the help wanted Extra attention is needed label Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant