Stefan Behnel wrote:
> Dag Sverre Seljebotn wrote:
>> Cython currently segfaults when using a buffer in nogil and accessing
>> out of bounds (which triggers an IndexError). This is a bug, however I
>> would like to do more than disallow it.
>>
>> I.e. what should happen here:
>>
>>      cdef object[int] buf = ... # buffer of length < 6
>>      with nogil:
>>          buf[5] = 0
>>
>> Option 1) Reacquire the GIL temporarily to construct the IndexError
>> instance. This seems to work wonderfully in my current patch; but is it
>> too unintuitive to raise an exception from an operation in a nogil
>> section?
> 
> Well, exceptions happen to be the error reporting mechanism in Python. In
> any case, the above must exit the nogil block immediately and should not
> crash (as long as we can prevent it in a reasonable way). To me, this
> sounds like an exception is the right thing.

However if the disadvantages outweighs the benefits... also, as Robert 
says, exception control flow would "water out" the nogil.

I'm OK with waiting for a GIL if an exception is raised, but on a mere 
function call seems much worse.

How about

  a) only flag for exceptions while in nogil, using a thread-local variable
  b) upon exiting the nogil section a 
ExceptionRaisedWhileInNoGilSectionError can be raised?
  c) Possibly add a function cython.nogil_exception_occurred so that 
exceptions can be checked for in nogil sections.

Try/except cannot ever be used in nogil sections after all.

After all, requiring compiler directives explictly silencing exceptions 
doesn't seem better than getting the exception a little late :-)

BTW, does anybody know if there's perhaps a way of querying 
PyErr_Occurred without the GIL, by Python-interpreter-dependant hacks if 
necesarry? It's just a read of a flag which is likely pointed to by a 
thread-local variable after all.

If this could be done I'm all for exception propagation in nogil 
sections (and a GIL is automatically acquired if exception must be 
constructed).

-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to