Skip to content

Instantly share code, notes, and snippets.

@JustusAdam
Created July 24, 2020 08:03
Show Gist options
  • Save JustusAdam/3e5c7b2b0f04d32ccdf85930d47441d5 to your computer and use it in GitHub Desktop.
Save JustusAdam/3e5c7b2b0f04d32ccdf85930d47441d5 to your computer and use it in GitHub Desktop.
interrupt_handler = lambda _: None
def foo():
global interrupt_handler
# also could be something like write to a channel, opened only locally in foo
def h(x):
print(x)
interrupt_handler = h
for i in bar():
print(i)
def bar():
yield 4
yield 3
baz()
yield 1
def baz():
# somehow force bar to `yield`
# or `return` 2
interrupt_handler(2)
print(foo())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment