Embedded Python - Blocking Python Function

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Nov 16 01:03:07 CET 2007


En Thu, 15 Nov 2007 16:18:45 -0300, <andy at britishideas.com> escribió:

> On Nov 15, 9:43 am, a... at britishideas.com wrote:
>> On Nov 14, 4:20 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
>> wrote:
>>
>> > Not forcibly - you need some cooperation from the Main function. Maybe
>> > setting a global variable that Main checks periodically.
>
> It works but the problem is that the script will be written by the end
> user. If they make a mistake and the cancel flag isn't perodically
> checked then it seems I have no way of cleanly ending the interpreter.
> If I wait for a specific time after requesting the Main function stop
> I need to be able to kill the interpreter without a runtime error. Any
> ideas?

You could use PyThreadState_SetAsyncExc - it's supposed to raise an  
exception in another thread. There is a Cookbook recipe using it here  
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960>
I've never actually used it, but I want to try it some day, so please  
report back your findings if you decide to use this function.

-- 
Gabriel Genellina




More information about the Python-list mailing list