Inter process communication using Tk/send hangs on suspended processes 
Author Message
 Inter process communication using Tk/send hangs on suspended processes

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

--

=====   R&D, Nonius BV, Delft   http://www.*-*-*.com/ ;           =====
===== PGPid 0xFA19277D ========================== Use Linux! =========



Sat, 03 Aug 2002 03:00:00 GMT  
 Inter process communication using Tk/send hangs on suspended processes
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.


Quote:
> 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

> --

> =====   R&D, Nonius BV, Delft  http://www.nonius.nl/             =====
> ===== PGPid 0xFA19277D ========================== Use Linux! =========
> --
> http://www.python.org/mailman/listinfo/python-list

--



Sun, 04 Aug 2002 03:00:00 GMT  
 Inter process communication using Tk/send hangs on suspended processes
Another approach entirely: Why not have an xmlrpcserver started right at the
beginning, and have each subsequent program register their details with the
server when they start up, and get the details they require from the server
about the other programs? This server could maintain all sorts of state, and
act as a central messaging service if need be...

Cheers,
        Mark

Quote:

>> 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?

--

Phone  - +61 9 380 3482           /     \               Department of Chemistry
Fax    - +61 9 380 1005      ---> *_,-._/   The University of Western Australia
                                       v                               Nedlands
Loc    - 31.97 S, 115.81 E                               Western Australia 6009


Mon, 05 Aug 2002 03:00:00 GMT  
 Inter process communication using Tk/send hangs on suspended processes




 >> >> 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).
 >>
 GM> The only things I can think of are to fork separate processes to
 GM> do each send and kill them if they do not respond quickly.
 >>  That doesn't work, as this will result in X requests that arrive
 >> out-of-order. As far as I know, no 2 processes can share their X
 >> socket connection. I guess I'll have to investigate the "server"
 >> concept.

 GM> That is only true if you fork without exec'ing and are not
 GM> careful about closing the inherited file descriptors.  What I
 GM> meant was to fork *and exec* another process, passing in
 GM> information like the X display using the command line arguments.

Yikes, that sounds really expensive: execing another python process,
and importing Tkinter in there..... I guess I could do one fork/exec
for all queries. I'll have a look.

The alternative idea of a server that is automatically (re-)started to
keep a centralized database sounds very nice as well. More work to get
started, but very powerful!

Thanks for all help,

Rob Hooft.

--

=====   R&D, Nonius BV, Delft  http://www.nonius.nl/             =====
===== PGPid 0xFA19277D ========================== Use Linux! =========



Sat, 10 Aug 2002 03:00:00 GMT  
 Inter process communication using Tk/send hangs on suspended processes

Quote:


>  >> 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).

>  GM> The only things I can think of are to fork separate processes to
>  GM> do each send and kill them if they do not respond quickly.

> That doesn't work, as this will result in X requests that arrive
> out-of-order. As far as I know, no 2 processes can share their X
> socket connection. I guess I'll have to investigate the "server"
> concept.

That is only true if you fork without exec'ing and are not careful
about closing the inherited file descriptors.  What I meant was to
fork *and exec* another process, passing in information like the X
display using the command line arguments.

--



Sun, 11 Aug 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Inter-process communication in Unix and Tcl/TK

2. VSE 3.11 and Inter-process communication

3. Smalltalk-to-Smalltalk inter-process communication

4. Inter-Process Communication

5. Inter Thread/Process communication

6. Inter-process communication

7. Inter-process communication options

8. Asynchronous Inter Process Communication in a Prolog debugger

9. Inter-process communication

10. Inter Process Communication with python

11. portable Inter Process Communication

12. inter-process communication

 

 
Powered by phpBB® Forum Software