[Tim Peters]
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. .... 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
[Dieter Maurer]
This may even be portable (not Windows specific). At least, it works for Linux2.
I believe it is portable, but the Unix version of this code doesn't use sockets at all. It uses a pipe instead. A pipe can't be used on Windows because the Windows select() works only with sockets, and asyncore on Windows uses select(). I don't know if/why a pipe would be better on Unix, but just assume that it is. I do know that the Windows version of this code used to leak sockets madly, for years. The pipe code is simpler still.
In this case, we might get rid of the stupid code duplication...
Well, there are two kinds: 1. Massive code duplication between the "posix" and "not posix" versions of the `trigger` classes. I already refactored ZODB's copy to eliminate that (most of the ZODB 3.4 trigger code is in a shared base class now, and the "posix" and "not posix" versions override just enough to make the pipe-versus-socket-pair distinction). 2. Massive code duplication between ZODB's copy and Medusa's. Hmm. Since I refactored ZODB's copy, it's hard to tell that they have anything in common anymore ;-)