[Numpy-discussion] Handling interrupts in NumPy extensions
Travis Oliphant
oliphant at ee.byu.edu
Thu Aug 24 20:11:09 EDT 2006
David M. Cooke wrote:
>On Aug 24, 2006, at 18:38 , Travis Oliphant wrote:
>
>
>
>>You can already use the approach suggested:
>>
>>if (PyOS_InterruptOccurred()) goto error
>>
>>to handle interrupts. The drawback of this approach is that the loop
>>executes more slowly because a check for the interrupt occurs many
>>times
>>in the loop which costs time.
>>
>>The advantage is that it may work with threads (I'm not clear on
>>whether
>>or not PyOS_InterruptOccurred can be called without the GIL, though).
>>
>>
>
>It should be; it's pure C code:
>
>int
>PyOS_InterruptOccurred(void)
>{
> if (!interrupted)
> return 0;
> interrupted = 0;
> return 1;
>}
>
>
I tried to test this with threads using the following program and it
doesn't seem to respond to interrupts.
import threading
import numpy.core.multiarray as ncm
class mythread(threading.Thread):
def run(self):
print "Starting thread", self.getName()
ncm.test_interrupt(1)
print "Ending thread", self.getName()
m1 = mythread()
m2 = mythread()
m1.start()
m2.start()
More information about the NumPy-Discussion
mailing list