[Twisted-Python] ENOBUF and Twisted
andrew-twisted at puzzling.org
Thu Aug 19 05:10:07 EDT 2004
On Thu, Aug 19, 2004 at 09:31:31AM +0200, Grzegorz Makarewicz wrote:
> screwtape at froup.com wrote:
> >A colleague of mine was working with a server written in Twisted
> >today, and he ran into a problem involving Twisted. He called me over
> >(since I'm supposed to be the Python Guru here, which just means I'm
> >slightly less ignorant than everybody else :) and we tracked the
> >behaviour in question all the way down to twisted.internet.tcp.
> This is not a bug
> select says "yes there is room inm the socket buffer"
> however datagram protocols do not store anythign in the outgoing socket
> buffer, but, instead hand the packets directly to the driver for the
> when the NIC fils up it returns ENOBUFS
> use sleep(0.01) between calls to socket.send
Using sleep in Twisted would be a bad idea -- if you have other sockets on
other network cards, you should just work on servicing them rather than
stopping everything. It's possible there's other work to do other than
socket operations, too, e.g. servicing any pendingTimedCalls (created by
reactor.callLater). In short, time.sleep should not be used in the Twisted
main thread, let alone the reactor itself.
If the only sane way to deal with this is to wait 100ms and try again, then
I'd try this:
[ ... caught ENOBUFS ... ]
reactor.callLater(0.1, reactor.addReader, sock)
This might interact badly with other systems that try to add/remove that
reader (consumers/producers maybe?), but is probably good enough for
screwtape's particular case.
I wonder if the win32reactor or iocpreactor get more useful information than
select and so can handle this better?
More information about the Twisted-Python