handle_connect called when connection fails

ebnf@h... ebnf@h...
Thu, 26 Oct 2000 13:42:55 -0000

The following code tries to connect to a port that no one is listening
to - the problem is that handle_connect is called anyway. Is there
anyway I can find out whether the connection failed without trying to
write or read (which I imagined would fail).

import asyncore

class test (asyncore.dispatcher):
def __init__ (self):
asyncore.dispatcher.__init__ (self)

def handle_connect (self):
print 'Connected'

if __name__ == '__main__':
import socket

t = test()
t.create_socket(socket.AF_INET, socket.SOCK_STREAM)
# there's nobody listening on 9879
t.connect(('localhost', 9879))

Thanks in advance.