You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Curio separates socket construction logic into separate *_server_socket synchronous functions. This gives ability to start listening in synchronous context, then do something with the socket, e.g. get actual bound port number when port=0 was passed to auto select, and only after that start accepting connections in asynchronous context.
This is the use case that may be beneficial in unit tests, for example, consider the following scenario:
Create a socket without any specific port, bind it and listen (sync)
Get bound port number
Spin up client thread / process with the port number obtained in part 2 (sync)
Start accepting incoming connections (async)
I think it would be a great addition and this is really easy to implement.
The text was updated successfully, but these errors were encountered:
The difference is in the context. In your example socket is created and bound is async context. From there the only way to pass it back to sync context is to use threads and thread synchronization primitives. You cannot "yield" from anyio.run. I think the approach where socket is created in plain old blocking way is more versatile. But I understand that this is debatable.
Curio separates socket construction logic into separate *_server_socket synchronous functions. This gives ability to start listening in synchronous context, then do something with the socket, e.g. get actual bound port number when port=0 was passed to auto select, and only after that start accepting connections in asynchronous context.
This is the use case that may be beneficial in unit tests, for example, consider the following scenario:
I think it would be a great addition and this is really easy to implement.
The text was updated successfully, but these errors were encountered: