1👍
✅
Well, the p
variable does indeed not exist in your context of status == False
.
You could use a pidfile
where you write down p
‘s pid
when the command is ran with status == True
and kill (os.kill
would work well) the process whose pid
is in that pidfile
when you run the command is ran with status == False
.
You probably make the whole thing a bit simpler by just writing down the pid
of the Python script that’s running the subprocess command in the first place and kill that one.
That’s not very graceful however.
Source:stackexchange.com