Threading woes

Grant Edwards grante at visi.com
Fri Jan 26 19:53:23 EST 2001


In article <v%nc6.3118$xn.831173 at typhoon2.ba-dsg.net>, David Allen wrote:

>Now my question.  I'm trying to implement a STOP button. When the user
>clicks it, the program should stop what it's doing *IMMEDIATELY* and go
>idle.  Currently I've got STOP implemented, but it's horribly broken, and
>only somewhat works half of the time.  :)

Ah well, at least your Windows users will be happy.  ;)

[...]

>I know there's some technique I'm missing, or an approach that I just don't
>know about.  I just need a solution that meets 2 criteria:

Once you've got a socket open, you can add a read callback so that the
interpreter will call a given function any time there is data available. It
will process GUI events as normal when no data is waiting.

>- It allows my Tkinter GUI to not be hung, it processes events as normal so
>  if the user decides to grab a 40 terabyte file, the app doesn't hang.

Stopping during download is easy using the read callback method.

>- It is interruptable at any moment.  (i.e. if 
>  networking is down, and I call gethostbyname

That's the tricky part...  

The only thing I can think of is to open a pipe to another process that's
doing the lookup and hook a read callback to that pipe.  That way you can
kill the process when somebody hits STOP.

It should work in Unix, but can you hook a callback to a pipe in Win32?

-- 
Grant Edwards                   grante             Yow!  UH-OH!! I put on
                                  at               "GREAT HEAD-ON TRAIN
                               visi.com            COLLISIONS of the 50's"
                                                   by mistake!!!



More information about the Python-list mailing list