Wednesday, 15 August 2012

linux - how can I stop python script without killing it? -


I want to know that there is a way to stop the dragon script when it's running, without killing it.

For example, I know that ctrl + z or c will kill existing processes .. but I do not want to kill the program ..

My The Python program takes one file at a time and executes some jobs. Each file takes approximately 10 ~ 20 minutes depending on the size of the file .. and there are many files in one directory.

But sometimes I have to give it to eliminate that file He is currently working on stopping the program after the current file instead of hitting it in the middle of the work.

How can I do this in Python? I want to write this dragon coding if I can ..

I have tried

  if os.path.exists (filename) sys exit (0)  

But this is the one, I have to create a file, while it's running so that when it reaches that file, it stops ... but instead of doing it .. I have to see what is the best way to stop it.

I have to end this file sometimes The current hit it in the middle of working on stopping the work rather than just program the current file

It is more specific than Ctrl + Z; You are asking to stop the program, but not yet. You can use the signals for this, set a signal handler with Signals , and open it with the kill -SIGWHATEVER on the command line. Signal handler, generally speaking, should only set one flag that you check periodically; It really should be "nothing" by yourself, because you do not know when your program has been called.

A signal handler is a function that is called when your program receives signal sent by using kill program, or kill () is sent from the system call. For files in files: # stop stop = transmitted stop = true signal Signal (signal. SIUISR1, handler): # or whatever looks like your main loop # stop if the process of a file: brake


No comments:

Post a Comment