Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: uses=Executor should work with spawn start method (#3380)
- Loading branch information
Tadej Svetina
committed
Sep 10, 2021
1 parent
b0e46a3
commit 2cf15df
Showing
9 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from jina import Executor | ||
|
||
|
||
class Exec(Executor): | ||
pass |
15 changes: 15 additions & 0 deletions
15
tests/integration/multiprocessing_spawn/modules/main_cls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from multiprocessing import get_start_method | ||
|
||
import jina | ||
|
||
|
||
def run(): | ||
from exec import Exec | ||
|
||
with jina.Flow().add(uses=Exec) as f: | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
assert get_start_method() == 'spawn' | ||
run() |
15 changes: 15 additions & 0 deletions
15
tests/integration/multiprocessing_spawn/modules/main_empty.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from multiprocessing import get_start_method | ||
|
||
import jina | ||
|
||
|
||
def run(): | ||
from exec import Exec | ||
|
||
with jina.Flow().add() as f: | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
assert get_start_method() == 'spawn' | ||
run() |
15 changes: 15 additions & 0 deletions
15
tests/integration/multiprocessing_spawn/modules/main_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from multiprocessing import get_start_method | ||
|
||
import jina | ||
|
||
|
||
def run(): | ||
from exec import Exec | ||
|
||
with jina.Flow().add(uses="Exec") as f: | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
assert get_start_method() == 'spawn' | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Tests that flow can launch when using the spawn multiprocessing method | ||
Currently when using class name this still breaks (see xfail) | ||
""" | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
|
||
import pytest | ||
|
||
|
||
def test_launch_spawn_empty(): | ||
subprocess.run( | ||
[sys.executable, 'main_empty.py'], | ||
check=True, | ||
env={'JINA_MP_START_METHOD': 'spawn', 'PATH': os.environ['PATH']}, | ||
cwd=Path(__file__).parent / 'modules', | ||
) | ||
|
||
|
||
def test_launch_spawn_cls(): | ||
print(sys.executable) | ||
subprocess.run( | ||
[sys.executable, 'main_cls.py'], | ||
check=True, | ||
env={'JINA_MP_START_METHOD': 'spawn', 'PATH': os.environ['PATH']}, | ||
cwd=Path(__file__).parent / 'modules', | ||
) | ||
|
||
|
||
@pytest.mark.xfail(reason="re-importing not possible when given only exec name") | ||
def test_launch_spawn_name(): | ||
subprocess.run( | ||
[sys.executable, 'main_name.py'], | ||
check=True, | ||
env={'JINA_MP_START_METHOD': 'spawn', 'PATH': os.environ['PATH']}, | ||
cwd=Path(__file__).parent / 'modules', | ||
) |