Issue85

Title PyThreadState_SetAsyncExc not work?
Priority bug Status done-cbb
Superseder Nosy List nssh
Assigned To Keywords

Created on 2013-03-25.03:42:25 by nssh, last changed by kayhayen.

Messages
msg292 (view) Author: kayhayen Date: 2013-03-25.21:48:57
I have added support for async exceptions to the threading. Async exceptions are 
now raise eventually:

import ctypes, time, threading

class AsyncExc(Exception):
        pass
try:
    result = 
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(threading.get_ident()), 
ctypes.py_object(AsyncExc))
    while 1:
        print( ".", end = "", flush = True )
        time.sleep(0.1)
except AsyncExc:
    print("success")
else:
    print("failed")

Notice the loop, without it fails. 

Python3.2 declares all relevant indicators "static" in ceval.c. This precludes 
us from being able to integrate with it. I shall check how this could be solved, 
if at all. It may require upstream cooperation.
msg288 (view) Author: kayhayen Date: 2013-03-25.10:02:29
I think this is along the same lines as CTRL-C. I recall seeing tstate->async_exc 
or something there and thinking it would be solved too.

The thing is, "time.sleep()" maybe won't trigger the raise, but it may occur only 
at loop ends. I would have to check. I think "SetAsyncExc" will set the counter 
to 0, so that next loop end will raise.

Too slow async exceptions, are no fun. This needs more thought.
msg286 (view) Author: nssh Date: 2013-03-25.03:42:25
Maybe I should set the status to deferred, but I don't known the reason of this.
code
import ctypes, time, threading
class AsyncExc(Exception):
	pass
try:
	result =
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(threading.get_ident()),
ctypes.py_object(AsyncExc))
	time.sleep(2)
except AsyncExc:
	print("success")
else:
	print("failed")

result
$ python3 ../1.py 
success
$ python3 ./bin/nuitka-python --python-version=3.3 ../1.py 
failed
Exception __main__.AsyncExc in <module 'threading' from
'/usr/lib/python3.3/threading.py'> ignored
History
Date User Action Args
2013-03-25 21:48:57kayhayensetstatus: chatting -> done-cbb
messages: + msg292
2013-03-25 10:02:29kayhayensetstatus: unread -> chatting
messages: + msg288
2013-03-25 03:42:25nsshcreate