-
-
Notifications
You must be signed in to change notification settings - Fork 174
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
serialize only the global variables used by function #86
Conversation
def capture_output(f): | ||
stdout = sys.stdout | ||
sys.stdout = StringIO() | ||
f() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly, should we parse the byte code by ourselves?
cc @JoshRosen |
@davies: Ok, interesting… If I get the time to play with it today, I will try to get back to you this evening. From what I see, I expect there will be a few small cleaning/changes before it goes in. |
@mmckerns Thanks, any comments are welcome. detect.py depends on dill.py, so I'm not detect.py is the perfect place to put the change in. |
In python 3 you could use import dis
def to_int(x):
if not isinstance(x, int):
return ord(x)
return x
def find_globals(co):
globs = set()
code = co.co_code
n = len(code)
i = 0
extended_arg = 0
while i < n:
op = to_int(code[i])
i = i+1
if op >= dis.HAVE_ARGUMENT:
oparg = to_int(code[i]) + to_int(code[i+1]) * 256 + extended_arg
extended_arg = 0
i = i+2
if op == dis.EXTENDED_ARG:
extended_arg = oparg * 65536
if op in dis.hasname and dis.opname[op].endswith("_GLOBAL"):
globs.add(co.co_names[oparg])
return globs |
@davies: yeah, that's part of what should be resolved, along with some naming, and as @matsjoyce points out, some comparability issues. |
@matsjoyce @mmckerns Could you take over this patch? I think that will be easier to merge. |
@davies: Ok, sure, I/we will do that. I'm a bit backed up at the moment, but will get to it hopefully soon. One thing you can do in the meantime is to make sure your patch works for test cases in #50, provide any further cases it does/doesn't work, and any further feedback on the proposed changes/requirements from #50. Thanks for the initial submission. I'll merge it when changes/updates ready are to go. |
@matsjoyce: I don't get the same results from your code as I do from @davies. Just FYI. @davies: I have a question for you… what would you expect from something like this:
Would you expect:
I definitely think what is currently in the |
Ok, obviously this is a high-priority to wrap-up. I'll finish this off first opportunity. |
edited this PR heavily, then added the 'essence' of it in: fadbffc Issues arose that removed functionality from dill in certain corner cases (e.g. If I can remove the conflict, I can remove the flag (or make the default |
added global setting |
Looks good. Just one question: why is it called |
The major difference is whether or not |
This PR try to fix the issue in #50