QThread.terminate in Python 3

Lee Harr missive at hotmail.com
Fri Sep 28 22:04:00 EDT 2012


>> I understand that use of QThread.terminate is discouraged,
>> but it has worked well previously and I would like to continue
>> this use if possible.
>>
>       And now you've encountered the reason it is discouraged.

Ok. Point taken.

What I hear you saying is that once I use .terminate anything
following that is indeterminate. It might work on my system
and nowhere else. Even though it was working for me before,
it was likely causing trouble elsewhere.


So, I need another approach.

The problem I am facing is that I want to run arbitrary
(user-supplied) code in the other thread and need to be
able to stop it at any time.

This is for a python turtle-graphics application:
http://pynguin.googlecode.com/


I found another possible approach here:
http://tomerfiliba.com/recipes/Thread2/

It uses ctypes to raise an exception in the other thread.
For the simple test case, at least, it works (for me).

Is this any safer or more reliable than .terminate ?

Is it portable? ie, if I build this in to my actual application
and it works for me, is it likely to work for everyone?


Thanks for any insight.

 		 	   		  



More information about the Python-list mailing list