Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
killing a script
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Cameron Simpson, post: 4240661"] | On Tue, 30 Aug 2011 08:53 am Arnaud Delobelle wrote: | >> Yes, but if I am not mistaken, that will require me to put a line or | >> two after each os.system call. That's almost like whack-a-mole at the | >> code level rather than the Control-C level. OK, not a huge deal for | >> one script, but I was hoping for something simpler. I was hoping I | >> could put one line at the top of the script and be done with it. | > | > Write a function! That's what they're for after all :) | | I'm not sure that this is actually as simple as that, especially using | os.system. | | As I understand it, the scenario is this: | | The main script looks something like this: | | for x in whatever: | os.system('something.py x') | | Each time through the loop, a new Python process is started. Each process | runs in the foreground, capturing standard input, and so hitting Ctrl-C | kills *that* process, not the main script. Unless, by chance, the Ctrl-C | happens after the system call returns, but before the next one starts, it | is completely invisible to the parent process (the main script). Wrapping | os.system in a function does nothing to fix that. Presuming you're talking about UNIX, this is not correct. Ctrl-C at the terminal delivers SIGINT to _every_ process in the controlling process group for the terminal. It also has _nothing_ to do with the standard input. When you run a script, yea even a Python script, thus: myscript ... then job control capable shells (all of them, these days) put the python process running "myscript" in its own process group as the leader (being, initially, the only process in the group). If myscript forks other processes, as happens in os.system(), they are _also_ in that process group. _ALL_ of them receive the SIGINT from your Ctrl-C. Cheers, [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
killing a script
Top