Skip to content

Commit

Permalink
chore: try fix setting start method (#5896)
Browse files Browse the repository at this point in the history
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai>
  • Loading branch information
JoanFM committed May 30, 2023
1 parent 042b580 commit bae0363
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
10 changes: 9 additions & 1 deletion jina/__init__.py
Expand Up @@ -55,7 +55,15 @@ def _warning_on_one_line(message, category, filename, lineno, *args, **kwargs):
# https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods
from multiprocessing import set_start_method as _set_start_method

_set_start_method('fork')
try:
_set_start_method('fork')
_warnings.warn(
f'multiprocessing start method is set to `fork`'
)
except Exception as e:
_warnings.warn(
f'failed to set multiprocessing start_method to `fork`: {e!r}'
)

# do not change this line manually
# this is managed by git tag and updated on every release
Expand Down
27 changes: 9 additions & 18 deletions jina/helper.py
Expand Up @@ -1310,25 +1310,16 @@ def run(self):
if loop and loop.is_running():
# eventloop already exist
# running inside Jupyter
if is_jupyter():
thread = _RunThread()
thread.start()
thread.join()
try:
return thread.result
except AttributeError:
from jina.excepts import BadClient

raise BadClient(
'something wrong when running the eventloop, result can not be retrieved'
)
else:
thread = _RunThread()
thread.start()
thread.join()
try:
return thread.result
except AttributeError:
from jina.excepts import BadClient

raise RuntimeError(
'you have an eventloop running but not using Jupyter/ipython, '
'this may mean you are using Jina with other integration? if so, then you '
'may want to use Client/Flow(asyncio=True). If not, then '
'please report this issue here: https://github.com/jina-ai/jina'
raise BadClient(
'something wrong when running the eventloop, result can not be retrieved'
)
else:
return asyncio.run(func(*args, **kwargs))
Expand Down

0 comments on commit bae0363

Please sign in to comment.