Closed
Description
So I assume that Ray runs everything in one thread. Especially because of this code.
This is important for us, because then we can know that we can for example capture all output in #817.
But, playing a bit, there are some thread issues. For example, the following snippet:
from pip.utils import logging as pip_logging
import ray
ray.init()
@ray.remote
def f():
with pip_logging.indent_log():
pass
return "foobar"
print(ray.get(f.remote()))
fails with:
Traceback (most recent call last):
File "test.py", line 14, in <module>
print(ray.get(f.remote()))
File ".../lib/python3.5/site-packages/ray/worker.py", line 1603, in get
Remote function __main__.f failed with:
Traceback (most recent call last):
File "test.py", line 9, in f
with pip_logging.indent_log():
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File ".../lib/python3.5/site-packages/pip/utils/logging.py", line 34, in indent_log
_log_state.indentation += num
AttributeError: '_thread._local' object has no attribute 'indentation'
_thread._local
is a thread-local dict. The code itself could be improved to not have this issue, but the question is why does not initialize it correctly, and how could I make it initialize correctly this module?
(An easy way is to move from pip.utils import logging as pip_logging
inside f
, but the issue is that we are importing those all around the code, so it is already imported somewhere else when we get to f
.)
Metadata
Metadata
Assignees
Labels
No labels