-
Notifications
You must be signed in to change notification settings - Fork 40
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
Conversation
@bensteers Awesome! Thanks for this! Will take a look at it early this week. |
@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. |
jupyternotify/jupyternotify.py
Outdated
@@ -2,16 +2,24 @@ | |||
# for more details on the implementation here | |||
import json | |||
import uuid | |||
import time |
There was a problem hiding this comment.
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?
jupyternotify/jupyternotify.py
Outdated
|
||
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 |
There was a problem hiding this comment.
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
?
Glad you like! I alphabetized the imports. Let me know of any other changes. |
@bensteers @htorrence is going to do a full code review. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
jupyternotify/jupyternotify.py
Outdated
pass # can't convert to string. Use default message | ||
|
||
# allow notify to stop autonotify | ||
if not self.__class__.notification_uuid: return |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
``` | ||
`autonotify` also takes the arguments `--message` / `-m` and `--output` / `-o`. | ||
|
||
## Use cell output as message. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
LGTM! |
yay! Thanks for the review!! |
jupyternotify/jupyternotify.py
Outdated
default="Cell Execution Has Finished!!", | ||
help="Custom notification message" | ||
) | ||
@line_magic |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I expanded the functionality a bit.
autonotify
magic, which lets users automatically send notifications if a cell execution takes longer thanx
seconds