Skip to content

Commit

Permalink
👯‍♀️ magic vipas
Browse files Browse the repository at this point in the history
  • Loading branch information
raynardj committed Dec 1, 2021
1 parent 373cd49 commit 807c735
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 6 deletions.
2 changes: 1 addition & 1 deletion forgebox/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.18.4"
__version__ = "0.4.18.5"
1 change: 1 addition & 0 deletions forgebox/_nbdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"compare_sentences": "06_spacy.ipynb",
"highlight": "06_spacy.ipynb",
"FreeMap": "07_freemap.ipynb",
"VipaClass": "09_multiprocess.ipynb",
"SingleFileLiner": "09_multiprocess.ipynb",
"DataFrameRowling": "09_multiprocess.ipynb",
"Stuff": "10_loop.ipynb",
Expand Down
35 changes: 34 additions & 1 deletion forgebox/multiproc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/09_multiprocess.ipynb (unless otherwise specified).

__all__ = ['SingleFileLiner', 'DataFrameRowling']
__all__ = ['VipaClass', 'SingleFileLiner', 'DataFrameRowling']

# Cell
from pathlib import Path
import logging
from typing import List, Dict, Callable, Any, Tuple
import random
from multiprocessing import Process

# Cell
class VipaClass:
"""
From meditation word Vipassana
Where creating a magic function
you can run a cell without holding the entire notebook
```ipython
%%vipas
...do things
```
"""
def __init__(self):
self.procs = []

def vipas(self, line, cell):
"""
run a cell magic function, that will not hold the process
"""
ishell = get_ipython()
proc = Process(target=ishell.run_cell, args = (cell,), daemon=True)
proc.start()
self.procs.append(proc)

try:
ishell = get_ipython()
from IPython.core import magic
vipa_class = VipaClass()
magic.register_cell_magic(vipa_class.vipas)
vipas = vipa_class.vipas
except:
pass

# Cell
class SingleFileLiner:
Expand Down
53 changes: 50 additions & 3 deletions nbs/09_multiprocess.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,62 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# export\n",
"from pathlib import Path\n",
"import logging\n",
"from typing import List, Dict, Callable, Any, Tuple\n",
"import random"
"import random\n",
"from multiprocessing import Process"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Separate Process Magic"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# export\n",
"class VipaClass:\n",
" \"\"\"\n",
" From meditation word Vipassana\n",
" Where creating a magic function\n",
" you can run a cell without holding the entire notebook\n",
" ```ipython\n",
" %%vipas\n",
" ...do things\n",
" ```\n",
" \"\"\"\n",
" def __init__(self):\n",
" self.procs = []\n",
"\n",
" def vipas(self, line, cell):\n",
" \"\"\"\n",
" run a cell magic function, that will not hold the process\n",
" \"\"\"\n",
" ishell = get_ipython()\n",
" proc = Process(target=ishell.run_cell, args = (cell,), daemon=True)\n",
" proc.start()\n",
" self.procs.append(proc)\n",
" \n",
"try:\n",
" ishell = get_ipython()\n",
" from IPython.core import magic\n",
" vipa_class = VipaClass()\n",
" magic.register_cell_magic(vipa_class.vipas)\n",
" vipas = vipa_class.vipas\n",
"except:\n",
" pass"
]
},
{
Expand Down Expand Up @@ -264,7 +311,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ author = xiaochen(ray) zhang
author_email = [email protected]
copyright = xiaochen(ray) zhang
branch = master
version = 0.4.18.4
version = 0.4.18.5
min_python = 3.6
audience = Developers
language = English
Expand Down

0 comments on commit 807c735

Please sign in to comment.