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

Realtime printing #28

Merged
merged 7 commits into from
Sep 27, 2021
Merged

Realtime printing #28

merged 7 commits into from
Sep 27, 2021

Conversation

eriknw
Copy link
Owner

@eriknw eriknw commented Sep 26, 2021

Closes #13.

  • Use events added to the latest distributed release to send print statements back to the client in realtime.
  • We now always try to capture print statements.
  • Also, we never block to display print statements or displaying the repr of the final expression (previously, we would block if not running in e.g. Jupyter Notebook).

Q1: is it safe to assume that events sent from a single task will be received in correct order (FIFO)? This appears to be the case.
Q2: should we also print on the worker?

CC @gjoseph92

@gjoseph92
Copy link

Thank you! Very excited about this.

Q1: is it safe to assume that events sent from a single task will be received in correct order (FIFO)? This appears to be the case.

I think so? That is, I don't think we're explicitly enforcing this, so it's probably theoretically possible to get out of order (unless we get some guarantees from TCP somehow), but seems very unlikely? @fjetter might know better since he added this feature.

Q2: should we also print on the worker?

Probably yes, since that's what distributed.print is doing right now. Could get a little weird running a local cluster in a non-Jupyter notebook (double prints), but why don't we go with yes for now.

@eriknw
Copy link
Owner Author

eriknw commented Sep 27, 2021

Cool, let's give this a try! Thanks for the input and pointing me to the distributed PR (dask/distributed#5217) that enables this.

I have another question: do you know of any alternatives to using ipywidgets.Output to asynchronously update cell outputs? I don't like how it requires an active kernel to display the outputs. Alternatively, is there some way to "persist" the Output object when we know we're finished updating it?

If out-of-order print statements become an issue, we can use the timestamps to ensure they're displayed in the correct order.

afar/_core.py Outdated
pretty_repr = repr_afar(results.return_value, magic_func._repr_methods)
if pretty_repr is not None:
try:
worker.log_event(channel, (unique_key, "display_expr", pretty_repr))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to rework this. worker.log_event doesn't raise here--it raises an exception on the client instead. It also doesn't provide a return value that can be used to determine whether the log was successful or not.

I think the solution for afar is to not display the rich repr of objects that use _ipython_display_ or find some other workaround.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't provide a return value that can be used to determine whether the log was successful or not.

if that's helpful, we can change it

@eriknw eriknw merged commit e8ddf59 into main Sep 27, 2021
@eriknw eriknw deleted the async_print branch September 27, 2021 17:51
@fjetter
Copy link

fjetter commented Sep 27, 2021

Q1: is it safe to assume that events sent from a single task will be received in correct order (FIFO)? This appears to be the case.

Yes

Q2: should we also print on the worker?

no strong opinion ¯_(ツ)_/¯

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 this pull request may close these issues.

Send print statements back to the client
3 participants