[Python-bugs-list] [ python-Bugs-231273 ] [windows] os.popen doens't kill subprocess when interrupted
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 10 Jul 2002 23:57:15 -0700
Bugs item #231273, was opened at 2001-02-07 03:43
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=231273&group_id=5470
Category: Windows
Group: Platform-specific
Status: Open
Resolution: None
Priority: 5
Submitted By: Christophe Gouiran (cgouiran)
Assigned to: Mark Hammond (mhammond)
Summary: [windows] os.popen doens't kill subprocess when interrupted
Initial Comment:
Hi, in the following script I liked to make an interface to the contig program(http://www.sysinternals.com)
As the popen invocation can be a long time process (since it walks recursively trough directories) I press CTRL-C sometimes and the contig continues to run.
I use Python 2.0 (BeOpen version) under WinNT 4.0(SP 4)
Maybe I made a mistake in the following script ?
-------------------------------------------------
#! /usr/bin/env python
import sys;
import os;
import re;
content = ""
mm = re.compile("Processing (.+)?:\nFragments: (\d+)?");
output = os.popen("contig -a -s *.*");
while(1):
line = output.readline();
if line == '':
break
content += line;
status = output.close()
if status:
print("Error contig : "+`status`+"("+os.strerror(status)+")");
sys.exit(12);
print mm.findall(content)
----------------------------------------------------------------------
>Comment By: Mark Hammond (mhammond)
Date: 2002-07-11 16:57
Message:
Logged In: YES
user_id=14198
Martin: you wrote:
> I can't see the bug here, though - why *should*
> terminating the parent process terminate the child
> processes also?
I think there is a bug here - certainly a difference
compared to Linux. Consider a script popen_child.py:
import time
for i in range(20):
print i
time.sleep(1)
and consider popen_parent.py
import os
f=os.popen("python popen_child.py")
print f.read()
f.close()
When popen_parent.py is executed on Linux and I press
Ctrl+C, I see *both* processes terminate with
KeyboardInterrupt. On Windows, the parent process is killed
but the child continues until it dies of other causes.
I may be able to fix it but now I am not even sure it is a
bug :)
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2001-06-05 06:46
Message:
Logged In: YES
user_id=21627
A patch for this problem is in progress at
https://sourceforge.net/tracker/index.php?func=detail&aid=403743&group_id=5470&atid=305470
I can't see the bug here, though - why *should*
terminating the parent process terminate the child
processes also?
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-02-10 10:50
Message:
Poor Mark. I assign anything with "popen + Windows" to you, because you're the only one who ever makes progress on them <wink>. Offhand, I can't see how Ctrl+C directed at Python *could* interrupt a spawned process.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=231273&group_id=5470