Skip to content

Conversation

@raulchen
Copy link
Contributor

@raulchen raulchen commented Jul 5, 2018

Move import thread and related functions to a separate file, and make it a class.
Note: this PR is simply a sanitizing refactor, it doesn't change any code logic. Next RP will change the import thread to use its own redis client and local scheduler client to address multi-threading issue. Previous discussion can be found at #2248.

from __future__ import print_function

import pickle
import ray
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import ray should be grouped with the other ray imports below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard style of my previous company is putting all imports before all from ... imports. I checked pep8 and google style, they doesn't seem to have a particular rule regarding this, but this style looks cleaner to me. Do we want to consider this? (That being said, I'll follow the current style in this PR.)

Also, I'm seeing something like import ray.ray_constants as ray_constants, I think we should avoid this and use from ray import ray_constants



class ImportThread(object):
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring should contain a one-line description, e.g.,

"""Brief one-line description of the class.

More details....

Attributes:
    worker: ...
"""

function_id = ray.ObjectID(function_id_str)
function_name = function_name.decode("ascii")
max_calls = int(max_calls)
module = module.decode("ascii")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you rebase on the current master, all of the decode("ascii") lines should be replaced by ray.utils.decode. E.g., see eaa1110.

This has better behavior in Python 2.

t.start()

def _run(self):
from ray.worker import log_span, WORKER_MODE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of this code was changed in #2306

from __future__ import division
from __future__ import print_function

import pickle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be pickle, it should be import ray.cloudpickle as pickle (grouped with the ray imports below)

@raulchen
Copy link
Contributor Author

raulchen commented Jul 5, 2018

(Copying my previous comment here because it was out-dated)

The standard style of my previous company is putting all imports before all from ... imports. I checked pep8 and google style, they doesn't seem to have a particular rule regarding this, but this style looks cleaner to me. Do we want to consider this? (That being said, I'll follow the current style in this PR.)

Also, I'm seeing something like import ray.ray_constants as ray_constants, I think we should avoid this and use from ray import ray_constants instead.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6482/
Test FAILed.

@robertnishihara
Copy link
Collaborator

robertnishihara commented Jul 5, 2018

@raulchen We should defer to whatever the google style guide says (or any Python standards).

@concretevitamin are you more familiar with this?

As for from ray import ray_constants, my personal preference is just import ray.ray_constants, which is more verbose. I don't feel very strongly about this one.

Let's avoid usage of from X import Y as much as possible. I've run into issues where sometimes Y has not been defined yet, so it can be safer to do just import X. I remember running into this in #1774.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6485/
Test PASSed.

@raulchen
Copy link
Contributor Author

raulchen commented Jul 5, 2018

hi @robertnishihara,
Google style organizes imports in 4 groups.
Within each group, imports are sorted lexicographically.
See https://github.com/google/styleguide/blob/gh-pages/pyguide.md#313-imports-formatting.

And it uses import x to import single-level modules, and uses from x.y import z to import multi-level modules.
See https://github.com/google/styleguide/blob/gh-pages/pyguide.md#224-decision

I'll change the code according to the above rules.

Also, import x.y and from x import y should be equivalent in terms of how a module is imported by the interpreter. It only make differences in how you reference y. See https://stackoverflow.com/questions/710551/use-import-module-or-from-module-import
Thus regarding the issue you mentioned above, I don't think from import is the culprit. I didn't dig deep, it seems to me that the problem is circular imports.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6487/
Test FAILed.

@raulchen
Copy link
Contributor Author

raulchen commented Jul 6, 2018

hi @robertnishihara, could you please help re-run the Travis CI? test failures look unrelated. Thank you!

@raulchen
Copy link
Contributor Author

raulchen commented Jul 6, 2018

Close and reopen this PR to trigger Travis CI.

@raulchen raulchen closed this Jul 6, 2018
@raulchen raulchen reopened this Jul 6, 2018
@robertnishihara
Copy link
Collaborator

jenkins, retest this please

if self.mode != WORKER_MODE:
if key.startswith(b"FunctionsToRun"):
with profile(
"ray:import_function_to_run",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test failure in the "xray" Travis job is caused by the name changes in these profile statements. This PR changes them accidentally (due to the rebase). Do you see what I mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. thank you for pointing out.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6568/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6569/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6573/
Test PASSed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/6574/
Test PASSed.

@raulchen
Copy link
Contributor Author

raulchen commented Jul 9, 2018

@robertnishihara this PR should be ready now.

@raulchen raulchen mentioned this pull request Jul 10, 2018
3 tasks
@pcmoritz pcmoritz merged commit d6af507 into ray-project:master Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants