Skip to content

Commit 8cdc7a2

Browse files
committed
fixes #550
1 parent 24a10e8 commit 8cdc7a2

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

fastcore/all.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
from .meta import *
1010
from .imports import *
1111
from .script import *
12+
from .xml import *

fastcore/parallel.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@
2020
except: pass
2121

2222
# %% ../nbs/03a_parallel.ipynb 4
23-
def threaded(f):
24-
"Run `f` in a thread, and returns the thread"
25-
@wraps(f)
26-
def _f(*args, **kwargs):
27-
res = Thread(target=f, args=args, kwargs=kwargs)
28-
res.start()
29-
return res
30-
return _f
23+
def threaded(process=False):
24+
"Run `f` in a `Thread` (or `Process` if `process=True`), and returns it"
25+
def _r(f):
26+
@wraps(f)
27+
def _f(*args, **kwargs):
28+
res = (Thread,Process)[process](target=f, args=args, kwargs=kwargs)
29+
res.start()
30+
return res
31+
return _f
32+
if callable(process):
33+
o = process
34+
process = False
35+
return _r(o)
36+
return _r
3137

3238
# %% ../nbs/03a_parallel.ipynb 6
3339
def startthread(f):

fastcore/xml.py

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def xt(tag:str, *c, **kw):
4545
# %% ../nbs/11_xml.ipynb 9
4646
def to_xml(elm, lvl=0):
4747
"Convert `xt` element tree into an XML string"
48+
if hasattr(elm, '__xt__'): elm = elm.__xt__()
4849
sp = ' ' * lvl
4950
if not isinstance(elm, list):
5051
if isinstance(elm, str): elm = escape(elm)

nbs/03a_parallel.ipynb

+14-8
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,20 @@
5858
"outputs": [],
5959
"source": [
6060
"#|export\n",
61-
"def threaded(f):\n",
62-
" \"Run `f` in a thread, and returns the thread\"\n",
63-
" @wraps(f)\n",
64-
" def _f(*args, **kwargs):\n",
65-
" res = Thread(target=f, args=args, kwargs=kwargs)\n",
66-
" res.start()\n",
67-
" return res\n",
68-
" return _f"
61+
"def threaded(process=False):\n",
62+
" \"Run `f` in a `Thread` (or `Process` if `process=True`), and returns it\"\n",
63+
" def _r(f):\n",
64+
" @wraps(f)\n",
65+
" def _f(*args, **kwargs):\n",
66+
" res = (Thread,Process)[process](target=f, args=args, kwargs=kwargs)\n",
67+
" res.start()\n",
68+
" return res\n",
69+
" return _f\n",
70+
" if callable(process):\n",
71+
" o = process\n",
72+
" process = False\n",
73+
" return _r(o)\n",
74+
" return _r"
6975
]
7076
},
7177
{

nbs/11_xml.ipynb

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"#| export\n",
148148
"def to_xml(elm, lvl=0):\n",
149149
" \"Convert `xt` element tree into an XML string\"\n",
150+
" if hasattr(elm, '__xt__'): elm = elm.__xt__()\n",
150151
" sp = ' ' * lvl\n",
151152
" if not isinstance(elm, list):\n",
152153
" if isinstance(elm, str): elm = escape(elm)\n",

0 commit comments

Comments
 (0)