-
Notifications
You must be signed in to change notification settings - Fork 12
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
IPython
integration 😎
#306
base: ctx_result_consumption
Are you sure you want to change the base?
Conversation
2218e86
to
346cf6e
Compare
2569815
to
bbdf3d9
Compare
346cf6e
to
7facf38
Compare
bbdf3d9
to
89240b9
Compare
7facf38
to
4444fdf
Compare
89240b9
to
e8568b7
Compare
4444fdf
to
0b3590c
Compare
658c760
to
f378e69
Compare
329ea3b
to
206a523
Compare
d0106b8
to
a5c6941
Compare
0b3590c
to
b046cd3
Compare
b046cd3
to
f05364c
Compare
a5c6941
to
37ec037
Compare
8b93a1b
to
2fe9a1a
Compare
af47834
to
8c9f1c4
Compare
Turns out there might be a better solution for what we actually want ( from @smurfix on gitter: import trio
import greenback as gb
AW=gb.await_
async def wat():
await trio.sleep(0.1)
return "yes"
async def run():
await gb.ensure_portal()
breakpoint()
pass
trio.run(run) which can be called from repl like:
with follow up from @oremanj actually using
also a further extended example 🏄🏼 $ python3.8 -c "import trio, greenback, code; trio.run(greenback.with_portal_run_sync, code.interact)"
>>> import trio
>>> from greenback import await_ as aw, async_context as acm
>>> async def task(interval, msg):
... while True:
... await trio.sleep(interval)
... print(msg)
...
>>> with acm(trio.open_nursery()) as nursery:
... nursery.start_soon(task, 2, "every two seconds")
... nursery.start_soon(task, 0.75, "every 3/4 second")
... aw(task(1.7, "every 1.7 seconds"))
...
every 3/4 second
every 3/4 second
every 1.7 seconds
every two seconds
every 3/4 second
every 3/4 second
every 1.7 seconds
every 3/4 second
every two seconds
^CTraceback (most recent call last):
File "/usr/lib/python3.8/code.py", line 90, in runcode
exec(code, self.locals)
File "<console>", line 4, in <module>
File "/usr/lib/python3.8/site-packages/greenback/_impl.py", line 653, in await_
raise exception_from_greenbacked_function
File "<console>", line 3, in task
File "/usr/lib/python3.8/site-packages/trio/_timeouts.py", line 75, in sleep
await sleep_until(trio.current_time() + seconds)
File "/usr/lib/python3.8/site-packages/trio/_timeouts.py", line 56, in sleep_until
await sleep_forever()
File "/usr/lib/python3.8/site-packages/trio/_timeouts.py", line 40, in sleep_forever
await trio.lowlevel.wait_task_rescheduled(lambda _: trio.lowlevel.Abort.SUCCEEDED)
File "/usr/lib/python3.8/site-packages/trio/_core/_traps.py", line 166, in wait_task_rescheduled
return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
File "/usr/lib/python3.8/site-packages/outcome/_sync.py", line 111, in unwrap
raise captured_error
File "/usr/lib/python3.8/site-packages/trio/_core/_run.py", line 1178, in raise_cancel
raise KeyboardInterrupt
KeyboardInterrupt
>>> |
To make this work anywhere we should teach Trio's task creation code to unconditionally create a Greenback portal in every new task; otherwise debugging at random breakpoints won't work. |
@smurfix agreed, this is already an issue with debugging single task crashes within a nursery as well. Currently on a task crash, you can't
Further, this probably plays best with the idea of a |
8c9f1c4
to
4b31973
Compare
This code is originally written (with much thanks) by @mikenerone:matrix.org. Adds a `tractor.trionics.ipython_embed()` which is `trio` compatible and allows straight up `await async_func()` calls in the REPL with expected default blocking semantics. More refinements to come including user config loading and eventually a foundation for what will be a console REPL + %magics for shipping work off to actor clusters and manual respawn controls and thus probably eventually obsoleting all the "parallel" stuff built into `ipython` B) Probably pertains to #130
4b31973
to
7f65d80
Compare
2fe9a1a
to
6120e99
Compare
Like it sounds, with more refinements to come!
This is a POC and seems to do about what I'd like; would appreciate lurker feedback 😉
ping @mikenerone, original author of the base
gist
s for this:TODO: