-
Notifications
You must be signed in to change notification settings - Fork 129
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
Ungraceful shutdown of python script can leave orphan processes #326
Comments
cc @hughleat |
I noticed this problem when I implemented an algorithm that e.g., with compiler_gym.make("llvm-v0") as env:
# do something here
with env.fork() as fork:
# do more things here
|
Hi @uduse, I believe what you want is already implemented in the base gym API. CompilerGym environments created by import os
import compiler_gym
def is_running(pid):
try:
os.kill(pid, 0)
return True
except OSError:
return False
# Demo make():
with compiler_gym.make("llvm-v0") as env:
env_pid = env.service.connection.process.pid
print("Environment", ("running" if is_running(env_pid) else "exited"))
# Demo fork():
with env.fork() as fkd:
fkd_pid = env.service.connection.process.pid
print("Forked", ("running" if is_running(fkd_pid) else "exited"))
# Check whether environments have closed:
print()
print("Environment", ("running" if is_running(env_pid) else "exited"))
print("Forked", ("running" if is_running(fkd_pid) else "exited")) Produces output:
See this colab notebook. Cheers, |
@ChrisCummins Oh thanks for letting me know! I checked the source code and didn't find |
Yes, those are safe to kill. Those processes are cBench binaries which are used to compute Cheers, |
🐛 Bug
CompilerGym uses a client/service architecture. Every time a
CompilerEnv
object is created, a CompilerService subprocess is started. The lifetime of the subprocess is managed by theCompilerEnv
. CallingCompilerEnv.close()
terminates the service:If for some reason
CompilerEnv.close()
is not called (either through a system or user error), the CompilerService will not be killed and will remain dormant indefinitely.To Reproduce
In one terminal, open a python interpreter and start a CompilerGym environment. Make a note of the interpreter and the environment's service process IDs:
In another terminal, kill the interpreter process, and observe that the CompilerGym environment's service is still running:
That process will remain dormant until explicitly killed, or the machine is rebooted.
Expected behavior
After some period of inactivity, the service should realize that it is no longer being used and should gracefully shutdown.
To the best of my understanding, it is not possible to guarantee that a subprocess shutdown routine can be called by the parent process, so the proposed workaround is to have a 'time to live' timer on each subprocess which will shut itself down if that period of inactivity is reached.
Workaround
If you suspect that there are dormant LLVM CompilerGym services and you are not currently running any CompilerGym python scripts, you can manually kill them using:
although this does not tidy up any temporary cache files that the environments have created.
Environment
Please fill in this checklist:
Additional context
See the documentation for more background on CompilerGym's client/service architecture.
The text was updated successfully, but these errors were encountered: