asynchat - operation could not complete w/ blocking

A

Andreas R.

Hi again,

I'm using Python's asynchat module for networking.
When calling the sendall() method of asynchat,
I sometimes get the error message "the operation
could not complete without blocking".

So how do I enable blocking with synchat, or otherwise fix this error?

Thanks for the help I've received with asynchat so far in this news group.

- Andreas
 
F

Fredrik Lundh

Andreas R. said:
I'm using Python's asynchat module for networking.
When calling the sendall() method of asynchat,
I sometimes get the error message "the operation
could not complete without blocking".

what sendall method ? to get proper output buffering with asynchat, use
"push" (or "push_with_producer").

</F>
 
A

Andreas R.

A

Andreas R.

Fredrik said:
what sendall method ? to get proper output buffering with asynchat, use
"push" (or "push_with_producer").

The problem I was having with push, is that is does not always send
complete packages.

The solution to this was to use sendall() instead, but sendall() gives
blocking error messages.

- Andreas
 
E

Erik Max Francis

Andreas said:
The problem I was having with push, is that is does not always send
complete packages.

The solution to this was to use sendall() instead, but sendall() gives
blocking error messages.

The purpose of asynchat's push methods is to queue outgoing data and
send it when possible. When you're complaining that it does not always
send complete packages, that strongly implies to me that you're
misunderstanding how socket transmissions work.

With TCP you're guaranteed that data will show up in the same order you
sent it. You're not at all guaranteed that it will show up in the same
chunks, or that you will get it all at the same time.

The only time you'd want to do use something like "sendall" is when you
really _do_ want to block until you make sure all the data is sent. So
if you're wondering why it blocks, that suggests a deep misunderstanding
in how TCP works.

If you want to use asynchat to transmit data, all you need to do is set
things up so that push handles them. Once that's the case, the data
will be transmitted when the socket is writable such that it doesn't
block. In other words, all you want to do is call
push/push_with_producer and leave it at that.
 
D

Dennis Lee Bieber

The problem I was having with push, is that is does not always send
complete packages.

The solution to this was to use sendall() instead, but sendall() gives
blocking error messages.
Somehow, the above seems logical... "push" probably doesn't "send
complete packages" because doing so would require blocking; instead it
sends what won't block, presuming "you" (the programmer) will code
whatever is needed to handle partial sends and put the rest out on a
later "push".

"sendall" may be sending everything, but it does so by blocking
until the other end acknowledges enough packets have been received to
ensure that no data is lost.
--
 
A

Andreas R.

Dennis said:
Somehow, the above seems logical... "push" probably doesn't "send
complete packages" because doing so would require blocking; instead it
sends what won't block, presuming "you" (the programmer) will code
whatever is needed to handle partial sends and put the rest out on a
later "push".

"sendall" may be sending everything, but it does so by blocking
until the other end acknowledges enough packets have been received to
ensure that no data is lost.

Yes, this is how I understood sendall. But why does it sometimes report
the error: (10035, 'The socket operation could not complete without
blocking')


- Andreas
 
F

Fredrik Lundh

(possible duplicate; reposted due to mail server problems)

"Andreas R." `wrote:

nope. asyncore uses it's own send implementation, and asynchat implements
proper buffering on top of asyncore's send via the push methods.

the reason that you could call sendall appears to be that asyncore gives you
access to *all* socket object attributes via dynamic inheritance, and nobody
thought of filtering out the sendall method (which is a rather recent addition
to the socket layer). this should probably be fixed.

</F>
 
F

Fredrik Lundh

Andreas R. said:
The problem I was having with push, is that is does not always send
complete packages.

that sounds like a bug on the receiving side. the network layer is free
to split things up however it likes, and it's up to your code to put things
together again properly.
The solution to this was to use sendall() instead, but sendall() gives
blocking error messages.

sendall is blocking per definition (and it doesn't send complete packages
either; it just loops until it has managed to hand everything over to the net-
work layer).

</F>
 
F

Fredrik Lundh

:

Yes, this is how I understood sendall. But why does it sometimes report
the error: (10035, 'The socket operation could not complete without
blocking')

in this context, that error message means "I cannot buffer more data right now,
please come back later".

"sendall" (which is designed for blocking sockets) treats that as an error, while
asyncore's send and push methods do the right thing (i.e. waits until the socket
layer signals that it's ready to handle more data).

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top