socket.send : (11, 'Resource temporarily unavailable')

Grant Edwards invalid at invalid
Fri Aug 14 16:12:20 CEST 2009

On 2009-08-14, Gabriel Rossetti <gabriel.rossetti at> wrote:

> I get a (11, 'Resource temporarily unavailable') error when I
> try to send a file using a socket. Is there s size limit?

No, there's no size limit.  However, there is a bandwidth
limit.  You can't shove bytes into the pipe faster than they
come out the other end (at least not over the long term).

> I tried sending a smaller file and ii poses no problem. Am I
> doing something wrong?

Yes.  If you want to have the socket in non-blocking mode, then
you have to catch EAGAIN and retry the operation.

> def sendMessage(host, port, msg):
>     if isinstance(msg, unicode):
>         msg = msg.encode("utf-8")
>     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>     sock.connect((host, port))
>     sock.setblocking(0)
>     totalsent = 0
>     while totalsent < len(msg):
>         sent = sock.send(msg[totalsent:])
>         if sent == 0:
>             raise RuntimeError, "socket connection broken"
>         totalsent = totalsent + sent
>     sock.close()

Grant Edwards                   grante             Yow! I didn't order any
                                  at               WOO-WOO ... Maybe a YUBBA
                                 ... But no WOO-WOO!

More information about the Python-list mailing list