Re: [f2py] cancel fortran module inside python shell
Pearu Peterson <[email protected]> Thu, 6 Jan 2011 14:05:48 +0200
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
Hi, It would be nice to add this signal handler hook to the f2py repo. The hook ought to be implemented similar to the `threadsafe` feature, say, using a statement `catchctrlc` or similar (or more general: `signal_convert(SIGINT, RuntimeError)`). Best regards, Pearu On Thu, Jan 6, 2011 at 1:21 PM, James Kermode <[email protected]>wrote: > If you're not too worried about memory leaks, it's possible to slightly > modify f2py to allow interrupts with Ctrl+C to be caught and turned into > Python exceptions. I've done this by changing the code generated by f2py to > call the fortran routine so that it installs a custom signal handler for the > SIGINT signal. A setjmp()/longjmp() trap is used to raise an exception if an > interrupt occurs inside the fortran routine. This technique also allows > Fortran routines to raise exceptions if an error occurs. You can see the > code I use to do this at the links below. > > James. > > > http://src.tcm.phy.cam.ac.uk/viewvc/jrk33/repo/trunk/QUIP/Tools/quippy/patch_f2py.py?revision=7798&view=co > > http://src.tcm.phy.cam.ac.uk/viewvc/jrk33/repo/trunk/QUIP/libAtoms/cutil.c?view=co > > On 5 Jan 2011, at 20:02, Kevin Mitchell wrote: > > > As far as I know there is no good way to implement this. The problem > > is that the Fortran code is called by the process running the python > > shell. Therefore the two cannot be distinguished at the operating > > system level. That said, it would be dangerous if python actually > > heeded your request and ceased running the module midway through > > because it might cause memory leaks or undefined behaviour since there > > is no way for python to know what Fortran is actually doing so that it > > can stop at an opportune time. > > > > On 1/5/11, Mark Andrews <[email protected]> wrote: > >> Hi, > >> I have a simple question, sorry if the answer is out there and my > >> googling missed it. > >> To cancel or interrupt a running python script inside a python shell > >> like e.g., ipython, I press 'ctrl+c'. > >> If I write a pure fortran program and run it from a linux bash shell, > >> I can also cancel by pressing "ctrl+c". > >> However, if I write a fortran module for python using f2py and run > >> that in a python shell, I can not cancel with "ctrl+c". The only way I > >> can interrupt it is (with linux) issuing a kill command to the entire > >> python shell process. > >> I was wondering if there is something I am missing? Is there something > >> I should add to the fortran code or maybe to the f2py command line > >> flags? > >> thanks, > >> Mark > >> > >> _______________________________________________ > >> f2py-users mailing list > >> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] > >> http://cens.ioc.ee/mailman/listinfo/f2py-users > >> > > > > _______________________________________________ > > f2py-users mailing list > > f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] > > http://cens.ioc.ee/mailman/listinfo/f2py-users > > -- > Dr James Kermode, Research Associate > Department of Physics, King's College London > Room: Strand 7.33, Tel: +44 (0)20 7848 2064 > http://www.jrkermode.co.uk > > > _______________________________________________ > f2py-users mailing list > f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] > http://cens.ioc.ee/mailman/listinfo/f2py-users > _______________________________________________ f2py-users mailing list f2py-users-Y4l6ocDipWCuvFJfX82//[email protected] http://cens.ioc.ee/mailman/listinfo/f2py-users