-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7865e2
commit b1a6f59
Showing
5 changed files
with
121 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
__pycache__/ | ||
.*.swp | ||
.DS_Store | ||
.ipynb_checkpoints | ||
.jarjar | ||
.venv*/ | ||
*.pyc | ||
*.sublime-project | ||
test.py | ||
update-pip.sh | ||
dist/ | ||
build/ | ||
jarjar.egg-info/ | ||
venv*/ | ||
.venv*/ | ||
build/ | ||
dist/ | ||
install.log | ||
jarjar-shell | ||
build/ | ||
.ipynb_checkpoints | ||
.jarjar | ||
jarjar.egg-info/ | ||
test.py | ||
update-pip.sh | ||
venv*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Python API Workflows | ||
|
||
Jarjar is great for letting you know when come snippet of code has finished | ||
executing, but configuring things properly can be a little bit of a hassle. | ||
|
||
A common workflow involves writing your code and then throwing a jarjar call | ||
at the end: | ||
|
||
```python | ||
from jarjar import jarjar | ||
jj = jarjar() | ||
|
||
def fun(long_list): | ||
results = [] | ||
for i in long_list: | ||
if i == 'something': | ||
results.append('something') | ||
else: | ||
results.append('something else') | ||
return results | ||
|
||
# run the process, notify on completion | ||
results = fun(a_long_list) | ||
jj.text('Process complete!') | ||
``` | ||
|
||
That looks good, but what if an exception was raised on the way? So maybe you | ||
edit like so: | ||
|
||
```python | ||
try: | ||
results = fun(my_long_list) | ||
jj.text('Process complete!') | ||
except Exception: | ||
jj.text('Process Failed?') | ||
``` | ||
|
||
That's great. But what if you want to run many such processes? Or what if you | ||
want to run the same process twice, getting a notification each time? What if | ||
you wanted to include the traceback within the message if there was an | ||
exception? | ||
|
||
You'll end up writing a lot more code just to handle jarjar notifications. | ||
Luckily, we wrote that code for you. | ||
|
||
## Jarjar decorator | ||
|
||
You can decorate a function and jarjar will handle exceptions for you. You'll | ||
get a notification whenever the function exits, and it will include the | ||
traceback if there was an exception: | ||
|
||
```python | ||
@jj.decorate | ||
def fun(long_list): | ||
# ... | ||
|
||
results = fun(my_long_list) | ||
``` | ||
|
||
## Jupyter cell magic | ||
|
||
Jupyter notebooks are becoming a standard in scientific work. Packaged with | ||
jarjar is a Jupyter magic so that users can be notified about a cell's | ||
execution. | ||
|
||
You first need to register the magic, and then you can use it freely. In one | ||
cell: | ||
|
||
```python | ||
from jarjar import jarjar | ||
jj = jarjar() | ||
|
||
jj.register_magic() | ||
``` | ||
|
||
Then in a later cell: | ||
|
||
```python | ||
%%jarjar | ||
results = fun(my_long_list) | ||
``` | ||
|
||
You'll get a notification whether your cell executed successfully or not, and it | ||
will include the traceback if there was an exception. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
jj = jarjar() | ||
|
||
@jj.decorate | ||
def f(a=1): | ||
def fun(a=1): | ||
time.sleep(a) | ||
kfkdfsk | ||
int('a') | ||
|
||
|
||
f(3) | ||
fun(3) |