8000 Added new features by beasteers · Pull Request #23 · ShopRunner/jupyter-notify · GitHub
[go: up one dir, main page]

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

Added new features #23

Merged
merged 13 commits into from
Nov 3, 2017
Merged

Added new features #23

merged 13 commits into from
Nov 3, 2017

Conversation

beasteers
Copy link

I expanded the functionality a bit.

  • Added line magic so that notifications can be triggered mid-cell
  • Added option to use the cell output as the notification message
  • Added autonotify magic, which lets users automatically send notifications if a cell execution takes longer than x seconds

@mdagost
Copy link
Contributor
mdagost commented Oct 29, 2017

@bensteers Awesome! Thanks for this! Will take a look at it early this week.

@mdagost
Copy link
Contributor
mdagost commented Nov 2, 2017

@bensteers These features look really, really awesome. Thank you so much! I'm going to try to get a detailed code review done today or tomorrow.

@@ -2,16 +2,24 @@
# for more details on the implementation here
import json
import uuid
import time
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a thing about alphabetizing imports. Could you put this import before import uuid please?


from IPython.core.getipython import get_ipython
from IPython.core.magic import cell_magic, Magics, magics_class
from IPython.core.magic import cell_magic, Magics, magics_class, line_cell_magic, line_magic
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about alphabetizing: could you make it cell_magic, line_cell_magic, line_magic, Magics, magics_class?

@beasteers
Copy link
Author
beasteers commented Nov 3, 2017

Glad you like! I alphabetized the imports. Let me know of any other changes.

@mdagost
Copy link
Contributor
mdagost commented Nov 3, 2017

@bensteers @htorrence is going to do a full code review.

Copy link
Contributor
@htorrence htorrence left a comment

Choose a reason for hiding this comment

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

@bensteers This looks great, just a couple of small questions/comments before we merge it in!

"--output", action='store_true',
help="Use last output as message"
)
@line_magic
8000 Copy link
Contributor

Choose a reason for hiding this comment

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

Why is autonotify line magic rather than cell magic? Since it depends on the run time of the cell it seems like it would make more sense as cell magic

Copy link
Author

Choose a reason for hiding this comment

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

It's line magic because you only specify it once, at the top of your notebook, in a similar vein to how you use %matplotlib inline to make plots show in your notebook. Then any cell that runs over a certain amount of time will issue a notification. If it were cell magic, it would imply that autonotify is only applied to that cell.

I basically wrote autonotify because I didn't want to have to write %%notify at the top of every one of my cells that I want notifications for.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah okay, that makes sense

pass # can't convert to string. Use default message

# allow notify to stop autonotify
if not self.__class__.notification_uuid: return
Copy link
Contributor

Choose a reason for hiding this comment

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

let's put return and pass on the next line for PEP8 compliance

Copy link
Author

Choose a reason for hiding this comment

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

lol yep. lazy late night coding :p

README.md Outdated
```


## Automatically trigger notification after a certain cell execution time.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's lose the period to mirror the other sections

README.md Outdated
8000
```
`autonotify` also takes the arguments `--message` / `-m` and `--output` / `-o`.

## Use cell output as message.
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, let's lose the period in the title

README.md Outdated
```python
import numpy as np
import time
# autonotify after 30 seconds
Copy link
Contributor

Choose a reason for hiding this comment

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

I initially thought this would notify at 30 seconds if execution was still ongoing - that seems like the preferred behavior to me, but I'm not sure how to implement that. If notification at the requested time is not possible I'd clarify the comment here that the notification only occurs when the cell finishes.

Copy link
Author

Choose a reason for hiding this comment

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

No, I definitely think the current implementation is the way to go. The idea is that, when I run a cell that takes 2 minutes to run (or 40 minutes which was the case last week), I want to know when the cell has finished executing so that I don't have to keep leaving Netflix to see if it's done yet.

If you wanted that functionality (notification after 30s), we could probably work that out. I think you would just have to create a separate thread in pre_run_cell that just waits 30 seconds to send the message, but I'm not really sure how useful that would be.

I was worried about the explanation not being clear, so I can try and further clarify the distinction.

Copy link
Author

Choose a reason for hiding this comment

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

I'm thinking that using --after might be a confusing option name and does kind of imply that it would trigger after 30 seconds regardless of whether the cell has finished running or not. I'm not sure what would be better to use though. Let me know if you have any ideas

@htorrence
Copy link
Contributor

LGTM!

@beasteers
Copy link
Author

yay! Thanks for the review!!

@mdagost mdagost merged commit 6dd1e3b into ShopRunner:master Nov 3, 2017
default="Cell Execution Has Finished!!",
help="Custom notification message"
)
@line_magic
Copy link
Contributor

Choose a reason for hiding this comment

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

@bensteers Hey there. I know it's already merged, but do you think it is possible to make autonotification appear if total amount of time for all currently runinng cells exceeds threshold and not just one cell? It would be more useful for little thresholds if you have multiple cells running -- every quite fast but together they should be notified and it is more convenient for multiple big cells so you get only one notification when they all are finished?

Copy link
Author

Choose a reason for hiding this comment

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

Hm, yeah that's a good idea. I don't think I know enough about Jupyter development to know how to do this off-hand. Do you know if IPython has a cell queue that we can access? It currently hooks into events that run before and after any cell execution, but as it is, it's totally naive about the cell queue.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I'm afraid I don't know about IPython much too. May be @mdagost have some ideas?

Also do you know if it is possible to get cell-id so we could scroll to the executed cell on finish?

Copy link
Author

Choose a reason for hiding this comment

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

I'm not finding anything in the IPython docs about getting the current cell id or a list of the queued cells. I don't really have the time to find where that information is stored as I'm swamped with school work, but if you're able to locate it, I can most likely implement what you're requesting.

I'd imagine it's located somewhere in the IPython interactive shell object (ip = get_ipython()) though that's just a guess. ip docs.

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.

4 participants
0