Inter process communication using Tk/send hangs on suspended processes
Greg McFarlane
gregm at iname.com
Wed Feb 16 06:54:53 EST 2000
The only things I can think of are to fork separate processes to do
each send and kill them if they do not respond quickly. The other way
was for each program to create a unique property on the X root window
that could be queried. But trawling through the Tk man pages and
sources, I did not find a Tk interface to this feature of X.
On 15 Feb, Rob W. W. Hooft wrote:
> I have a group of python programs. Whenever any new program is started,
> it will try to establish connections to each of the other ones
> using Tk/send (it is asking each for their background color, and will
> choose a new one for itself). This is done using "root=setup.setup()",
> the setup module is appended to this message.
>
> The problem occurs when any pre-existing program has been suspended:
> in such a case the Tk/send does not return. I also can not seem to set
> a timeout on the communications (my attempts are in commented
> code). Are there any better suggestions?
>
> Regards,
>
> Rob Hooft.
> --------------------------------------------------------------------
> #
> __version__ = '$Id: setup.py,v 1.9 1999/08/04 09:16:21 hooft Exp $'
> #
> # GUI Startup
> #
> # (C) Rob W.W. Hooft, Nonius BV, 1997--1999
> #
> import os,signal
> import Tkinter,Pmw
>
> TclError=Tkinter.TclError
>
> bgcolors=["grey85","#DFF","#DDF","#FDF","#FDD","#FFD","#DFD"]
>
> #def timeouthandler(sig,frame):
> # print "WARNING: no response from other Tk application."
> # raise TclError
>
> def usedcolors(root):
> used=[]
> names=list(root.winfo_interps())
> names.sort()
> names.reverse()
> for name in names:
> try:
> #signal.signal(signal.SIGALRM,timeouthandler)
> #signal.alarm(3)
> root.send(name, 'winfo name .')
> #signal.alarm(0)
> #signal.signal(signal.SIGALRM,signal.SIG_DFL)
> except TclError:
> # Inoperative window -- ignore it
> pass
> else:
> try:
> col=root.send(name,'no-bgcolor')
> used.append(col)
> except:
> pass
> return used
>
> def setscheme(root):
> try:
> bgcolor=os.environ['NONIUS_BGCOLOR']
> Pmw.Color.setscheme(root,background=bgcolor)
> except KeyError:
> # Now sample all others, and see what is in use. Choose a new one.
> u=usedcolors(root)
> for col in :
> if col in u:
> continue
> break
> else:
> print "No free background color"
> col="grey85"
> Pmw.Color.setscheme(root,background=col)
> root.tk.createcommand('no-bgcolor',lambda bgcolor=col: bgcolor )
> os.environ['NONIUS_BGCOLOR']=col
>
> def setup(idle=1):
> import Tkinter,Pmw
> Pmw.initialise(fontScheme='Pmw1',size=14)
> root=Tkinter._default_root
> setscheme(root)
> import balloon # Automatically initializes...
> # Set up idle task calls for "checkifcanceled"....
> if idle:
> import projtls
> projtls._ltt.setidletask(root.update)
> return root
>
>
>
> --
> ===== rob at hooft.net http://www.xs4all.nl/~hooft/rob/ =====
> ===== R&D, Nonius BV, Delft http://www.nonius.nl/ =====
> ===== PGPid 0xFA19277D ========================== Use Linux! =========
> --
> http://www.python.org/mailman/listinfo/python-list
>
--
Greg McFarlane INMS Telstra Australia gregm at iname.com
More information about the Python-list
mailing list