New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async_chat.push() can trigger handle_error(). undocumented. #42647
Comments
suppose you have a socket handled by your asynchat.async_chat class foo()
s.push(data)
bar() the following is executed in case of an error: foo()
s.push(data)
s.handle_error()
bar() this created an obscure bug, as the bar() assumed the send() always to avoid this, handle_error() can set a flag, which can be checked after PS: send() can easily fail. suppose we're reading from 2 sockets: A and |
Logged In: YES Not a bug. The control for deciding how to handle an error import asynchat
class MyAsyncChat(asynchat.async_chat):
error = 0
def handle_error(self):
self.error = 1
asynchat.async_chat.handle_error(self)
def push(self, data):
self.error = 0
asynchat.async_chat.push(self, data)
return self.error Also, the fact that async_chat.push() ends up trying to send |
Logged In: YES Push() sending data may indeed be the source of the problems here. There My current work around is indeed subclassing as you describe. However, it So a suggestion: push() should either not try to send, or should communicate Maybe push() not sending is the nicer of the two solutions. There is little If nothing is changed, the documentation should contain that handle_error() |
Logged In: YES Here's a subclass that doesn't send on push... class MyAsyncChat(asynchat.async_chat):
def push (self, data):
self.producer_fifo.push (simple_producer (data)) That's it. And according to my reading of asynchat and asyncore, while |
Logged In: YES Oh I fully agree that its easy to write a workaround. And that the error doesn't Right now, you wouldn't tell from the docs that push() will try to send data This creates all sorts of obscure behaviour: class MyAsyncProtocol(asynchat.async_chat):
def handle_connect(self):
self.foo = some_value_I_calculate
self.push( "hello!" )
class MyLoggingAsyncProcotol(MyAsyncProtocol):
def handle_connect(self):
MyAsyncProtocol.handle_connect(self)
print "Connection established with foo value %d" % self.foo
def handle_error(self):
print "Connection lost" Could produce the following output: I wouldnt expect this from the documentation: push() adds data to the output A simple solution would be to put all push()es at the end of the function so If only the docs would be adapted, it would still bother me to have to do the So, do you feel docs/code should be changed, and if so, which one? |
Logged In: YES If anything should be changed, I would say the docs. Though I believe that adding a note which reads something like the |
Logged In: YES Ok thanks. The example with handle_connect() is just one out of many btw: in There are indeed cases in which initiate_send() in a push() is practical. Aside |
Logged In: YES Manipulating the same socket in two threads is a fool's |
If this won't going to be fixed/modified I suggest to close this report |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: