[Tutor] how to pause or stop a running python script?

Alan Gauld alan.gauld at btinternet.com
Fri Jan 26 09:49:52 CET 2007

"Wong Vincent" <thian_seng at yahoo.com> wrote

>      If I use run a script which consist the following line:
>  -->os.popen("python c:\\test.py")
>  Is it possible for me to interrupt the pause/stop the running of 
> "test.py" halfway?

There is a recipe for this somewhere.

I don't think you can do it with vanilla popen because you
need the process ID. You can do some trickery using multiple
threads, or you can use lower level tools to launch the process
(spawn etc).

However you should look at the subprocess module which
supercedes popen. I strongly suspect that the Popen class
will have some options that help here, although I confess I
haven't actually tried it!


Alan G. 

More information about the Tutor mailing list