This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jjdmol
Recipients
Date 2005-12-15.09:15:42
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=516066

Oh I fully agree that its easy to write a workaround. And that the error doesn't 
propagate out of push(). It's just the question whether this is desired 
behaviour and expected behaviour after reading the documentation? If not, 
either the code or documentation ought to be modified.

Right now, you wouldn't tell from the docs that push() will try to send data 
(and thus fail, which is the only moment handle_error() can occur in the 
middle your code if you catch exceptions yourself).

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:
Connection lost
Connection established with foo value 42

I wouldnt expect this from the documentation: push() adds data to the output 
buffer, but the docs dont say or imply it can fail and thus trigger handle_error
().

A simple solution would be to put all push()es at the end of the function so 
that no more code is executed except maybe handle_error(). But as the 
example above shows, this is not always possible. Another solution would be 
one of your workarounds.

If only the docs would be adapted, it would still bother me to have to do the 
above for any but the most trivial of applications. But once the docs warns me 
for this behaviour, I at least know it from the start :)

So, do you feel docs/code should be changed, and if so, which one?
History
Date User Action Args
2007-08-23 14:36:28adminlinkissue1370380 messages
2007-08-23 14:36:28admincreate