From 807c73557cef03513818a17f40a0a3ff9f3a7094 Mon Sep 17 00:00:00 2001 From: raynardj Date: Wed, 1 Dec 2021 10:49:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=AF=E2=80=8D=E2=99=80=EF=B8=8F=20magic?= =?UTF-8?q?=20vipas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- forgebox/__init__.py | 2 +- forgebox/_nbdev.py | 1 + forgebox/multiproc.py | 35 +++++++++++++++++++++++++- nbs/09_multiprocess.ipynb | 53 ++++++++++++++++++++++++++++++++++++--- settings.ini | 2 +- 5 files changed, 87 insertions(+), 6 deletions(-) diff --git a/forgebox/__init__.py b/forgebox/__init__.py index d9ef2ea..b88a962 100644 --- a/forgebox/__init__.py +++ b/forgebox/__init__.py @@ -1 +1 @@ -__version__ = "0.4.18.4" +__version__ = "0.4.18.5" diff --git a/forgebox/_nbdev.py b/forgebox/_nbdev.py index 7ff3ce9..f88215b 100644 --- a/forgebox/_nbdev.py +++ b/forgebox/_nbdev.py @@ -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", diff --git a/forgebox/multiproc.py b/forgebox/multiproc.py index d3353c9..3fed27e 100644 --- a/forgebox/multiproc.py +++ b/forgebox/multiproc.py @@ -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: diff --git a/nbs/09_multiprocess.ipynb b/nbs/09_multiprocess.ipynb index 7a0c8fe..69340ab 100644 --- a/nbs/09_multiprocess.ipynb +++ b/nbs/09_multiprocess.ipynb @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -27,7 +27,54 @@ "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" ] }, { @@ -264,7 +311,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, diff --git a/settings.ini b/settings.ini index bd46678..02295be 100644 --- a/settings.ini +++ b/settings.ini @@ -7,7 +7,7 @@ author = xiaochen(ray) zhang author_email = b2ray2c@gmail.com copyright = xiaochen(ray) zhang branch = master -version = 0.4.18.4 +version = 0.4.18.5 min_python = 3.6 audience = Developers language = English