[Numpy-discussion] Handling interrupts in NumPy extensions

Travis Oliphant oliphant at ee.byu.edu
Thu Aug 24 19:11:09 CDT 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  
>>in the loop which costs time.
>>The advantage is that it may work with threads (I'm not clear on  
>>or not PyOS_InterruptOccurred can be called without the GIL, though).
>It should be; it's pure C code:
>         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()
        print "Ending thread", self.getName()

m1 = mythread()
m2 = mythread()

More information about the Numpy-discussion mailing list