Thanks for the responses! It sounds like there's just no way to send a
signal to C++.

Moving loops from C++ to Python around is not really a solution for us
because we need to be moving them in the other direction if they're to
be moved at all. This is molecular simulation code, so some of the
extensions will probably run for hours/days... For example, a dynamics
simulation needs to know if you're planning on killing it so that it
can print out the latest iteration. Other times, I'm just debugging
it, and I don't need it to run to completion.

Maybe the best solution would be to have the C++ code check some file
or something. Then I could write in the file "die gracefully" and it
would respond when it reads it.



Amos.



On Thu, Feb 4, 2010 at 3:00 AM,  <cplusplus-sig-requ...@python.org> wrote:
> Send Cplusplus-sig mailing list submissions to
>        cplusplus-...@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://mail.python.org/mailman/listinfo/cplusplus-sig
> or, via email, send a message with subject or body 'help' to
>        cplusplus-sig-requ...@python.org
>
> You can reach the person managing the list at
>        cplusplus-sig-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Cplusplus-sig digest..."
>
>
> Today's Topics:
>
>   1. how do i interrupt a C++ extension? (Amos Anderson)
>   2. Re: how do i interrupt a C++ extension? (Matthew Scouten (TT))
>   3. Re: how do i interrupt a C++ extension? (Ralf W. Grosse-Kunstleve)
>   4. Re: how do i interrupt a C++ extension? (Gustavo Carneiro)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 3 Feb 2010 12:24:13 -0800
> From: Amos Anderson <nitroa...@gmail.com>
> To: "Development of Python/C++ integration" <cplusplus-sig@python.org>
> Subject: [C++-sig] how do i interrupt a C++ extension?
> Message-ID:
>        <9e910971002031224i4ce2fb37i3543ec74500fe...@mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hello --
>
> I've got a python script with C++ extensions. Some of my extensions
> take a long time to complete, and I don't want to wait for them to
> finish when I'm debugging stuff. However, when I do Ctrl-C in my
> terminal, it's completely ignored. So it looks like python is trapping
> the signal, but apparently can't do anything with it until the
> extension returns control to the python script. I guess ideally,
> Ctrl-C would kill the extension and return control to python,
> generating an exception, but I'd also be ok if Ctrl-C killed the
> python script too.
>
> I've been googling around, but can't figure out how this seemingly
> simple (and desired) task is accomplished. Anybody know how to do it?
> Right now, the only solution is Ctrl-Z and kill %1 so I guess that
> works for now...
>
> thanks!
>
> Amos.
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 3 Feb 2010 15:22:11 -0600
> From: "Matthew Scouten (TT)" <matthew.scou...@tradingtechnologies.com>
> To: "Development of Python/C++ integration" <cplusplus-sig@python.org>
> Subject: Re: [C++-sig] how do i interrupt a C++ extension?
> Message-ID: <32490dff7774554a85d65d23a9f0f9380c585...@chiex01>
> Content-Type: text/plain;       charset="US-ASCII"
>
> There is no solution. This is a problem inherent in the way python
> handles the GIL, c extensions, and Signals. Details here:
> http://www.dabeaz.com/python/GIL.pdf see slide 22
>
> -----Original Message-----
> From:
> cplusplus-sig-bounces+matthew.scouten=tradingtechnologies....@python.org
> [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies....@py
> thon.org] On Behalf Of Amos Anderson
> Sent: Wednesday, February 03, 2010 2:24 PM
> To: Development of Python/C++ integration
> Subject: [C++-sig] how do i interrupt a C++ extension?
>
> Hello --
>
> I've got a python script with C++ extensions. Some of my extensions
> take a long time to complete, and I don't want to wait for them to
> finish when I'm debugging stuff. However, when I do Ctrl-C in my
> terminal, it's completely ignored. So it looks like python is trapping
> the signal, but apparently can't do anything with it until the
> extension returns control to the python script. I guess ideally,
> Ctrl-C would kill the extension and return control to python,
> generating an exception, but I'd also be ok if Ctrl-C killed the
> python script too.
>
> I've been googling around, but can't figure out how this seemingly
> simple (and desired) task is accomplished. Anybody know how to do it?
> Right now, the only solution is Ctrl-Z and kill %1 so I guess that
> works for now...
>
> thanks!
>
> Amos.
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
>
> ------------------------------
>
> Message: 3
> Date: Wed, 3 Feb 2010 13:42:21 -0800 (PST)
> From: "Ralf W. Grosse-Kunstleve" <r...@yahoo.com>
> To: Development of Python/C++ integration <cplusplus-sig@python.org>
> Subject: Re: [C++-sig] how do i interrupt a C++ extension?
> Message-ID: <124463.50752...@web111412.mail.gq1.yahoo.com>
> Content-Type: text/plain; charset=us-ascii
>
> It would be a nice feature to have, but in 8+ years working with Boost.Python 
> I never truly needed it.
>
> I figure if your extension runs a long time it must have some layers of 
> loops. If you can modify the
> extension code, I'd reorganize it to move the outer loop into Python. If the 
> extension is a function,
> I'd turn it into a class like this:
>
>  calc = calculation()
>  while (calc.is_not_finished()):
>    calc.inner_loop()
>
> If you figure out how to make Ctrl-C work portably (!), post it here!
>
> Ralf
>
>
> ----- Original Message ----
> From: Amos Anderson <nitroa...@gmail.com>
> To: Development of Python/C++ integration <cplusplus-sig@python.org>
> Sent: Wed, February 3, 2010 12:24:13 PM
> Subject: [C++-sig] how do i interrupt a C++ extension?
>
> Hello --
>
> I've got a python script with C++ extensions. Some of my extensions
> take a long time to complete, and I don't want to wait for them to
> finish when I'm debugging stuff. However, when I do Ctrl-C in my
> terminal, it's completely ignored. So it looks like python is trapping
> the signal, but apparently can't do anything with it until the
> extension returns control to the python script. I guess ideally,
> Ctrl-C would kill the extension and return control to python,
> generating an exception, but I'd also be ok if Ctrl-C killed the
> python script too.
>
> I've been googling around, but can't figure out how this seemingly
> simple (and desired) task is accomplished. Anybody know how to do it?
> Right now, the only solution is Ctrl-Z and kill %1 so I guess that
> works for now...
>
> thanks!
>
> Amos.
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
>
>
> ------------------------------
>
> Message: 4
> Date: Wed, 3 Feb 2010 23:57:29 +0000
> From: Gustavo Carneiro <gjcarne...@gmail.com>
> To: "Development of Python/C++ integration" <cplusplus-sig@python.org>
> Subject: Re: [C++-sig] how do i interrupt a C++ extension?
> Message-ID:
>        <a467ca4f1002031557q178dd19bnd15f98abf2f44...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> On Wed, Feb 3, 2010 at 9:42 PM, Ralf W. Grosse-Kunstleve 
> <r...@yahoo.com>wrote:
>
>> It would be a nice feature to have, but in 8+ years working with
>> Boost.Python I never truly needed it.
>>
>> I figure if your extension runs a long time it must have some layers of
>> loops. If you can modify the
>> extension code, I'd reorganize it to move the outer loop into Python. If
>> the extension is a function,
>> I'd turn it into a class like this:
>>
>>  calc = calculation()
>>  while (calc.is_not_finished()):
>>    calc.inner_loop()
>>
>> If you figure out how to make Ctrl-C work portably (!), post it here!
>>
>
> I wouldn't advise this solution exactly like this.  It may work, but is
> going to be slow.  Moving loops into Python makes the computation probably a
> lot slower.
>
> The solution I adopted for the NS-3 simulator (ns3.Simulator.Run()) was kind
> of hybrid.  There is an outer loop, and there is an API to run a single
> iteration of that loop.  The ns3.Simulator.Run() wrapper[1] runs iterations
> of the loop the following way: we run iterations while there are events to
> process; every 100 iterations we 1) acquire the GIL, 2) call
> PyErr_CheckSignals() and check the result of PyErr_Occurred(), 3) release
> the GIL again.
>
> [1] See _wrap_Simulator_Run in
> http://code.nsnam.org/ns-3-dev/file/0ca25e25b116/bindings/python/ns3module_helpers.cc
>
>
>> Ralf
>>
>>
>> ----- Original Message ----
>> From: Amos Anderson <nitroa...@gmail.com>
>> To: Development of Python/C++ integration <cplusplus-sig@python.org>
>> Sent: Wed, February 3, 2010 12:24:13 PM
>> Subject: [C++-sig] how do i interrupt a C++ extension?
>>
>> Hello --
>>
>> I've got a python script with C++ extensions. Some of my extensions
>> take a long time to complete, and I don't want to wait for them to
>> finish when I'm debugging stuff. However, when I do Ctrl-C in my
>> terminal, it's completely ignored. So it looks like python is trapping
>> the signal, but apparently can't do anything with it until the
>> extension returns control to the python script. I guess ideally,
>> Ctrl-C would kill the extension and return control to python,
>> generating an exception, but I'd also be ok if Ctrl-C killed the
>> python script too.
>>
>> I've been googling around, but can't figure out how this seemingly
>> simple (and desired) task is accomplished. Anybody know how to do it?
>> Right now, the only solution is Ctrl-Z and kill %1 so I guess that
>> works for now...
>>
>> thanks!
>>
>> Amos.
>> _______________________________________________
>> Cplusplus-sig mailing list
>> Cplusplus-sig@python.org
>> http://mail.python.org/mailman/listinfo/cplusplus-sig
>>
>> _______________________________________________
>> Cplusplus-sig mailing list
>> Cplusplus-sig@python.org
>> http://mail.python.org/mailman/listinfo/cplusplus-sig
>>
>
>
>
> --
> Gustavo J. A. M. Carneiro
> INESC Porto, Telecommunications and Multimedia Unit
> "The universe is always one step beyond logic." -- Frank Herbert
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: 
> <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100203/6215cc67/attachment-0001.htm>
>
> ------------------------------
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
> End of Cplusplus-sig Digest, Vol 17, Issue 7
> ********************************************
>



-- 
~<>~<>~<>~<>~<>~<>~<>~<>~
Amos G. Anderson
+1-626-399-8958 (cell)
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to