in reply to How to run multiple server processes under Tk?

Threads will work fine with Tk, AS LONG AS YOU CREATE THE THREADS BEFORE YOU CREATE THE MAIN Tk WINDOW.

So you will not be able to "launch a new thread with a button click", however, you can signal an existing thread to do something. Create 2 sleeping threads first, then start a Tk front-end to control them. Check out Tk-with-worker-threads for an example of how it can be done.

The shared hashes and sleeping thread setup is the basic model I use with Tk, and works fine on linux and windows( earlier version of Windows like 95, 98, Me; don't handle big shared hashes very well. But this example works.)

The thing to remember with Tk and shared variables in threads, is that Tk will not "know" what the shared data is, until it actively tries to read it. So you can't use a shared variable as a reference, and expect it to update automatically....you need a timer to repeatedly check it.


I'm not really a human, but I play one on earth. flash japh
  • Comment on Re: How to run multiple server processes under Tk?

Replies are listed 'Best First'.
Re^2: How to run multiple server processes under Tk?
by noslenj123 (Scribe) on Sep 20, 2005 at 17:22 UTC
    Sweet,

    I'm going to give that a try, it sounds promising. I'll post back my results....

      Great. I was thinking about it a little more, and thought about the problem of reading the socket in the thread, and passing the data back thru shared variables. I've yet to see a way in main, to read a filehandle (socket) in the thread. So you might have to work out a scheme of pushing your socket reads into a shared array in the thread, then in the Tk program, setup a timer to shift data off of the shared array. That is the way I would do it, but you may have luck finding a way to read filehandles cross-thread.

      I'm not really a human, but I play one on earth. flash japh