Movatterモバイル変換


[0]ホーム

URL:


Thread interruption

David Bolendb3l at fitlinxx.com
Fri Apr 27 15:58:10 EDT 2001


Yann Cointepas <yann.cointepas at chups.jussieu.fr> writes:> I made a program that is a graphical environment that is used to launch> user Python scripts. Each user script is executed in its own thread> "within" a common graphical environment provided by the main program. I> would like to allow the user to kill a script but I found no clean and> portable way to interrupt a thread from another thread.You really need to find a way for the threads themselves to recognizethe need to be interrupted and to exit upon request from thecontrolling environment.  Thus, interrupting one thread from anotherbecomes an issue of communicating the request to exit which the targetthread acts on at an appropriate time from its perspective.Threads are not externally interruptable (in general) in Python, norin many underlying OSs (at least not without a high risk of subsequentresource problems in the process).  It would be nice to have aportable way to have interruption support on a per-thread basis, but Iwouldn't look for it anytime soon.  Note that I'm not intimatelyfamiliar with pthreads, so someone more familiar with them might beable to point out some way to bypass Python a bit and signal anotherthread asynchronously.However, it might not be as bad as you think - I'm not sure what eachof your user "scripts" are doing, but presumably the controllingthread is watching the user scripts to be able to replicate feedbackto some presentation layer in the graphical environment for display,correct?  If that's the case, you should be able to find some point inthe per-script threading that can look to see if a flag or othersentinel has been set that it should exit and it can do so.  You mayhave some latency problems if the per-script threads get blocked forsome reason for lengthy periods of time, depending on design.---- David-- /-----------------------------------------------------------------------\ \               David Bolen            \   E-mail:db3l at fitlinxx.com  /  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    | /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \\-----------------------------------------------------------------------/


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp