Python task label

jerf at compy.attbi.com jerf at compy.attbi.com
Mon Feb 3 23:43:03 EST 2003


On Tue, 04 Feb 2003 02:37:16 +0000, Sam Marrocco wrote:
> Jeff--the app I'm writing is actually a port of a vb app I wrote. The app
> needs to know how many other 'instances' of itself are already running on
> the machine (there can be several) and the app's name is numbered. With
> the vb app, as it was initializing, I would check the task list for any
> applications named 'MyApp#' and then pick the next unused number and make
> the new app start as "MyApp#+1".
> 
> I'm uncertain how I might go about determining which apps are running if
> they're all named 'python.exe'. I don't like the idea of having "lock
> files" on disk identifying tasks. hmmmmmmm......

Well, first I'd make sure you're aware of the Win32all extensions. (Google
for it.) If not, that might help.

Second, what is the numbering for? What kind of thing is this doing? Are
you connecting to some number of limited resources? Is there some other,
better way to differentiate between the windows, like an open file name,
resource name, or current activity? Numbering windows strikes me as a last
resort, since unless they are *totally* identical, the differences between
the windows ought to make for good titles.

If the program is stable, perhaps you should run each new 'app' instance
in a thread, instead of a new process. Then they can all see the current
count, and easily communicate through Queues if necessary. A lot of
windows programs work this way, but I don't know exactly how, and whether
there is OS support for this way of working. Failing all else you can
always start the program with:

* Try to grab a socket, for the purposes of discussion let's say #8765. 
* If I fail, send a message to 127.0.0.1:8765 describing how to open
  the new instance and exit.
* If I succeed, start a thread listening on that socket which will
  receive those messages and start the new threads as appropriate,
  and open the first window, whatever it is.

Tkinter may not like that from what I hear, though, so you may also need a
GUI-only thread. This isn't *too* hard, actually, with Queues, but if
you've never done that before it may take a bit to get into it.

Just a few ideas; I don't do windows programming much.




More information about the Python-list mailing list