Saturday, 15 March 2014

linux - How to stop the python script -


I am trying to write a dragon script which also kills / stops its process with signals.

It runs each file at a time, sleeps at specific times and until it ends with complete directory files, depending on the processing time size of each file, 5 to 10 minutes of AAS -Cap happens.

However, when I sign, I want to close my program. It should not kill it yet. It should run the current file and later stop it.

So I can not use CTRL Z because it suspends the pid yet.

  stop = false def handler (number, frame): global stop stop = true signal. Signals (signal CGIsR1, handler) do not stop: #dot thing  

The above which I tried, but it kills it right away when I promptly sign it on all the files Even after doing the work goes into the infinite loop

What can I do to stop the process when I indicate, does it allow to process the existing file?

Install Signal Handler Bus for Signal. SIGTERM - and there is a State Variable Setup in your program inside it. You check each file when processing it.

It's really very simple - see the document here.

  incorrect for filename ("& lt; your dir>") for import name termination = os.listdir: if it ends: break process_next_file (filename) def Handler (sign, frame): End the global endpoint print ("Termination Requested") = True signal.signal (signal.SIGTERM, handler)  

(In addition, you use other signals - SIGINT is one when user ctrl + C presses for example)


No comments:

Post a Comment