[Zope] Running more than one instance on windows often block each other

Tim Peters tim.peters at gmail.com
Mon Jul 25 10:36:50 EDT 2005


[Sune B. Woeller]
>> ...
>> I can see (with the excellent (and free) 'Process
>> Explorer' from sysinternals) that the python
>> processes always opens port 19999, and connects by
>> that port to themselves on another port (for
>> instance 2550).
 
[Dieter Maurer]
> You can find the relevant code in
> "ZServer.medusa.thread.select_trigger.trigger.__init__"
>
> In principle, the code should try all sockets between
> "19999" down to "19950" and fail only when none of them
> could be bound to...

Yup.  ZODB has what looks like a copy/paste of this code, in
ZEO/zrpc/trigger.py.  I didn't realize where it came from originally
until you pointed out the Medusa code here.

Anyway, it so happens I rewrote ZEO's copy a few weeks ago, in ZODB
3.4.  The Windows part is much simpler there now.  I don't know why
the original might fail in the way Sune reported, but perhaps the
rewritten version would not.

Before:

            # tricky: get a pair of connected sockets
            host='127.0.0.1'
            port=19999
            while 1:
                try:
                    self.address=(host, port)
                    a.bind(self.address)
                    break
                except:
                    if port <= 19950:
                        raise BindError, 'Cannot bind trigger!'
                    port=port - 1
                    
            a.listen (1)
            w.setblocking (0)
            try:
                w.connect (self.address)
            except:
                pass
            r, addr = a.accept()
            a.close()
            w.setblocking (1)
            self.trigger = w

After:

            # Specifying port 0 tells Windows to pick a port for us.
            a.bind(("127.0.0.1", 0))
            connect_address = a.getsockname()  # assigned (host, port) pair
            a.listen(1)
            w.connect(connect_address)
            r, addr = a.accept()  # r becomes asyncore's (self.)socket
            a.close()
            self.trigger = w


More information about the Zope mailing list