开发者

Python: calling process.terminate() doesn't kill it

When I run the following code:

p = subprocess.Popen("...", shell=True)          
if p.poll() == None:
  p.kill()

The process is simply not killed. I'm on Windows.

I thought it was because of multithreading, I ran it in a single thread, still same thing.

Do you have any ideas why this could be happening?

Thanks

Update

I found the code that causes the problem:

whil开发者_Go百科e cur_time < self.time_limit:
            if p.poll() != None:
                too_much_time = False
                break
            time.sleep(0.1)
            cur_time += 0.1

I run this to make sure that the process doesn't take more than the time limit. Apparently that's why I can't kill the process.


Because you use shell=True, all you end up killing is the shell (cmd.exe process) itself.

Process groups are a relatively new feature of Windows and I don't know of any software apart from Task Scheduler that actually uses them yet.


It may be that the command you are running is setting the sigmask to ignore the kill signal. Can you try with another command? e.g make a script that sleeps in an infinite while and try to kill that

offtopic, I think shell arg doesn't mean anything on windows

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜