Skip to content

Commit f315261

Browse files
committed
moved inner_f to global scope
1 parent ecae7d2 commit f315261

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

pytorch_lightning/utilities/xla_device_utils.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import importlib
3+
from multiprocessing import Process, Queue
34

45
TORCHXLA_AVAILABLE = importlib.util.find_spec("torch_xla") is not None
56
if TORCHXLA_AVAILABLE:
@@ -8,27 +9,22 @@
89
xm = None
910

1011

12+
def inner_f(queue, func, **kwargs):
13+
try:
14+
queue.put(func(**kwargs))
15+
except Exception:
16+
import traceback
17+
traceback.print_exc()
18+
queue.put(None)
19+
20+
1121
def pl_multi_process(func):
1222
@functools.wraps(func)
1323
def wrapper(*args, **kwargs):
14-
15-
from multiprocessing import Process, Queue
16-
1724
queue = Queue()
18-
19-
def inner_f():
20-
try:
21-
queue.put(func(**kwargs))
22-
except Exception:
23-
import traceback
24-
25-
traceback.print_exc()
26-
queue.put(None)
27-
28-
proc = Process(target=inner_f, kwargs=kwargs)
25+
proc = Process(target=inner_f, args=(queue, func,), kwargs=kwargs)
2926
proc.start()
3027
proc.join()
31-
3228
return queue.get()
3329

3430
return wrapper

0 commit comments

Comments
 (0)