-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
[core] Use psutil.process_iter
to replace psutil.pids
#51123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -340,23 +340,21 @@ def _find_address_from_flag(flag: str): | |
|
||
# The --redis-address here is what is now called the --address, but it | ||
# appears in the default_worker.py and agent.py calls as --redis-address. | ||
pids = psutil.pids() | ||
addresses = set() | ||
for pid in pids: | ||
for proc in psutil.process_iter(["cmdline"]): | ||
try: | ||
proc = psutil.Process(pid) | ||
# HACK: Workaround for UNIX idiosyncrasy | ||
# Normally, cmdline() is supposed to return the argument list. | ||
# But it in some cases (such as when setproctitle is called), | ||
# an arbitrary string resembling a command-line is stored in | ||
# the first argument. | ||
# Explanation: https://unix.stackexchange.com/a/432681 | ||
# More info: https://github.com/giampaolo/psutil/issues/1179 | ||
cmdline = proc.cmdline() | ||
cmdline = proc.info["cmdline"] | ||
# NOTE(kfstorm): To support Windows, we can't use | ||
# `os.path.basename(cmdline[0]) == "raylet"` here. | ||
|
||
if len(cmdline) > 0 and "raylet" in os.path.basename(cmdline[0]): | ||
if _is_raylet_process(cmdline): | ||
for arglist in cmdline: | ||
# Given we're merely seeking --redis-address, we just split | ||
# every argument on spaces for now. | ||
|
@@ -2289,3 +2287,19 @@ def start_ray_client_server( | |
fate_share=fate_share, | ||
) | ||
return process_info | ||
|
||
|
||
def _is_raylet_process(cmdline: Optional[List[str]]) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about taking a proc object directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may prefer to use |
||
"""Check if the command line belongs to a raylet process. | ||
|
||
Args: | ||
cmdline: List of command line arguments or None | ||
|
||
Returns: | ||
bool: True if this is a raylet process, False otherwise | ||
""" | ||
if cmdline is None or len(cmdline) == 0: | ||
return False | ||
|
||
executable = os.path.basename(cmdline[0]) | ||
return "raylet" in executable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proc.pid
is set whenProcess
is constructed. No need to specify it inprocess_iter
.