Repository navigation
Conversation
| # not the python process PID as reported by os.getpid() | ||
| try: | ||
| pid = parent.pid | ||
| except AttributeError: |
There was a problem hiding this comment.
Can you comment when this exception is raised?
|
Hmm, I actually think the other solution you suggested ( |
There are many ID types in Once we have a unique identifier (hopefully not too long), it should be trivial to add a command-line argument to use it and then parse that argument in |
|
The |
By then it is too late, how can I communicate that pid to the child process? The sequence is
I think I have a proof-of-concept using |
|
closing in favor of #24968 |
When using ray inside a virtualenv on windows, python.exe as reported by sys.executable is a PEP397 launcher to the actual python as reported by os.getpid(): >>> import sys, os, psutil >>> >>> print(sys.executable) C:\temp\issue24361\Scripts\python.exe >>> os.getpid() 2208 >>> child = psutil.Process(2208) >>> child.cmdline() ['C:\\oss\\CPython38\\python.exe'] >>> child.parent().cmdline() ['C:\\temp\\issue24361\\Scripts\\python.exe'] >>> child.parent().pid 6424 When the agent_manager launches the agent process via Process::Process(), it gets the PID of the launcher process (6424), which is what is expected as an ID when registering the agent in the gRPC callback. But inside agent.py, the child process reports the PID via os.getpid(), which is 2208, and this is the wrong PID to register the agent. The solution proposed here is another version of #24905 that creates a int agent_id = rand(); before starting the python process, and passes the agent_id to the process.
Why are these changes needed?
When using ray inside a virtualenv on windows,
python.exeas reported bysys.executableis a PEP397 launcher to the actual python as reported byos.getpid():When the
agent_managerlaunches the agent process viaProcess::Process(), it gets the PID of the launcher process (6424), which is what is expected as an ID when registering the agent in the gRPC callback. But insideagent.py, the child process reports the PID viaos.getpid(), which is 2208, and this is the wrong PID to register the agent.The solution proposed here checks whether
os.getpid()'s parent is a python process, and if so assumes it is the launcher. It then sets this PID as theagent_pid. A different solution would be to pass the agent_pid in to the process as a command line parameter or an environment variable.Related issue number
Closes #24361, #23945
Checks
scripts/format.shto lint the changes in this PR.Is there a test for running the ray head process in a virtualenv (different than the runtime_env tests, which run the workers in a virtualenv/conda env)?