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

Issue with generators #10

Closed
DRayX opened this issue Dec 17, 2015 · 0 comments · Fixed by #11
Closed

Issue with generators #10

DRayX opened this issue Dec 17, 2015 · 0 comments · Fixed by #11

Comments

@DRayX
Copy link
Contributor

DRayX commented Dec 17, 2015

This library doesn't work if there are any generators in the stack as the compiled raise __traceback_maker actually executes without raising an error if flag 0x20 (CO_GENERATOR) is set.

Simple repro:

import sys
import tblib
import traceback

def foo():
  raise RuntimeError()
  yield

try:
  next(foo())
except:
  assert traceback.extract_tb(sys.exc_info()[2]) == traceback.extract_tb(
      tblib.Traceback(sys.exc_info()[2]).as_traceback())

In general, mucking around with code attributes isn't really safe, and in the worst case could potentially cause a segfault when the code is executed. The filename and name (the two that actually matter as they are used by the exception printing system) should be safe. I wouldn't touch nlocals, stacksize, or flags though. I have seen instances where the overridden nlocals causes the exec itself to throw because there are no locals which screws up the line numbers in the tracebacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant