Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ray cannot be used in regular Python interpreter. #349

Closed
robertnishihara opened this issue Mar 8, 2017 · 2 comments
Closed

Ray cannot be used in regular Python interpreter. #349

robertnishihara opened this issue Mar 8, 2017 · 2 comments
Labels
bug Something that is supposed to be working; but isn't

Comments

@robertnishihara
Copy link
Collaborator

robertnishihara commented Mar 8, 2017

Doing the following fails in a regular Python interpreter (it works in IPython).

import ray

@ray.remote
def f():
  return 1

It fails with

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rkn/Workspace/ray/python/ray/worker.py", line 1886, in remote
    return make_remote_decorator(num_return_vals, num_cpus, num_gpus)(args[0])
  File "/Users/rkn/Workspace/ray/python/ray/worker.py", line 1798, in remote_decorator
    function_id_hash.update(inspect.getsource(func).encode("ascii"))
  File "/Users/rkn/anaconda3/lib/python3.6/inspect.py", line 938, in getsource
    lines, lnum = getsourcelines(object)
  File "/Users/rkn/anaconda3/lib/python3.6/inspect.py", line 925, in getsourcelines
    lines, lnum = findsource(object)
  File "/Users/rkn/anaconda3/lib/python3.6/inspect.py", line 756, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

The error is probably the same as this https://mail.python.org/pipermail/python-list/2014-August/677076.html. The interpreter just compiles the code you type to bytecode, executes it, and throws away the source. That means that you can't get the source.

We don't actually need the inspect module. We're currently using it to get the source code to hash when we compute function IDs.

@robertnishihara
Copy link
Collaborator Author

Note (from #394), in Python 2, this will raise an IOError instead of an OSError. For example (from #394)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python2.7/site-packages/ray-0.0.1-py2.7.egg/ray/worker.py", line 2104, in remote
    return make_remote_decorator(num_return_vals, num_cpus, num_gpus)(args[0])
  File "/opt/conda/lib/python2.7/site-packages/ray-0.0.1-py2.7.egg/ray/worker.py", line 2014, in remote_decorator
    function_id_hash.update(inspect.getsource(func).encode("ascii"))
  File "/opt/conda/lib/python2.7/inspect.py", line 701, in getsource
    lines, lnum = getsourcelines(object)
  File "/opt/conda/lib/python2.7/inspect.py", line 690, in getsourcelines
    lines, lnum = findsource(object)
  File "/opt/conda/lib/python2.7/inspect.py", line 538, in findsource
    raise IOError('could not get source code')
IOError: could not get source code

@robertnishihara
Copy link
Collaborator Author

Fixed by #395.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to be working; but isn't
Projects
None yet
Development

No branches or pull requests

1 participant