What to await when creating new listener with start_server? #12981
-
I'm trying to determine why my Here is the function:
There are no errors when the My current kludge of a fix is to wait half a second in any function that requires the data connection to be available. Obviously, this is a bad solution, but I'm kind of at a loss for where to go with this. According to the documentation
Removing await from start_server (like below) fixes the exception, but results in the data connection not being ready for the next FTP command (even with my kludge of waiting before listing files.) I suspect this is the case, because on the client side I still get a connection refused error.
The only combination of awaiting that seems to work is what I have below, but this seems counter to what the documention says is a coroutine and what is not. And, I still have my problem of having to
I've been banging my head on this for a while, trying to find a solution, but coming up empty. I'm hoping someone will have a better idea of what's going on and how I might fix it so I don't have to use the silly kludge of a delay before sending anything over the data connection. Thanks much! (Edited out complete code listing to make things more readable. It's at https://github.com/DavesCodeMusings/ftpdlite/ if anyone cares.) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
my_server = await asyncio.start_server(cb, host, port) The Note that the event loop code is obsolescent. See the tutorial. Host addresses should be from |
Beta Was this translation helpful? Give feedback.
asyncio.start_server()
returns aServer
instance. It runs a background task which accepts connections as they occur, calling the callback each time this occurs. So the correct call pattern is:The
my_server
instance should be retained in case you need to issuemy_server.close()
but, aside from that, all connections are handled by the callback which gets reader and writer streams for that particular connections.Note that the event loop code is obsolescent. See the tutorial.
Host addresses should be from
socket.getaddrinfo()
.