dbirch997 / cantera

Automatically exported from code.google.com/p/cantera
1 stars 0 forks source link

Stopping OneD simulations in Python using Ctrl-C doesn't work #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run a OneD simulation, e.g. npflame1.py, from the command line
2. During the computation, try to stop the execution using Ctrl-C

What is the expected output? What do you see instead?
This should stop the program. Instead, the program is further executed and just 
the following lines appear in the console window:

 ^CTraceback (most recent call last):
   File "<string>", line 1, in <module>
 KeyboardInterrupt

What version of the product are you using? On what operating system?
r1617 on OS X 10.6.8

Please provide any additional information below.
Sometimes, the simulation just doesn't seem to converge, and I need to stop it 
and re-run it with modified input parameters. Right now, I have to close the 
entire terminal window, which just is not comfortable.
Actually, it would be nice if you could monitor the residuals and set a maximum 
execution time for a simulation, but I guess that's another story.

Original issue reported on code.google.com by thetruet...@googlemail.com on 3 Jul 2012 at 12:42

GoogleCodeExporter commented 9 years ago
This is a typical issue with Python C extensions. Python can only safely handle 
the KeyboardInterrupt exception while it's running Python code, but you're 
stuck in a loop inside the C function sim1D_solve. 

You can have ctrl+c terminate the Python process by adding this to the top of 
your script:

    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)

But that's obviously not a very good general solution, as it would have the 
same effect on interactive sessions where you expect ctrl+c to return you to 
the Python prompt.

Original comment by yarmond on 3 Jul 2012 at 5:16

GoogleCodeExporter commented 9 years ago
This is fixed for the Cython module in r2184.

Solving this for the legacy Python module would be much more complicated, and 
given that that module is on it's way out, probably not worth the effort.

Original comment by yarmond on 4 Mar 2013 at 5:38