Skip to content

Commit

Permalink
copied pl_multi_process
Browse files Browse the repository at this point in the history
  • Loading branch information
lezwon committed Sep 1, 2020
1 parent f315261 commit a4fa477
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pytorch_lightning/utilities/xla_device_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,29 @@ def inner_f(queue, func, **kwargs):


def pl_multi_process(func):
"""Wrapper for running multi-processing tests."""

@functools.wraps(func)
def wrapper(*args, **kwargs):

from multiprocessing import Process, Queue
queue = Queue()
proc = Process(target=inner_f, args=(queue, func,), kwargs=kwargs)

def inner_f(queue, **kwargs):
try:
result = func(**kwargs)
queue.put(result)
except Exception:
import traceback
traceback.print_exc()
queue.put(False)

proc = Process(target=inner_f, args=(queue,), kwargs=kwargs)
proc.start()
proc.join()
return queue.get()

result = queue.get()
assert result == 1, 'expected 1, but returned %s' % result

return wrapper

Expand Down

0 comments on commit a4fa477

Please sign in to comment.