Closed guyingbo closed 5 years ago
Quick comment: run_in_thread()
can take kwargs if you wrap it with partial()
or a lambda
. For example:
from functools import partial
await run_in_thread(partial(callable, keyword=value))
This is actually the recommended way to pass keyword arguments to all of Curio's functions that launch tasks, functions, and other similar things.
Can you say a bit more about this so._GLOBAL_DEFAULT_TIMEOUT workaround. I'm not really sure I understand the rest of this bug report on quick read.
Because python's socket.create_connection is defined as:
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
and curio's socket.create_connection is defined as:
@wraps(_socket.create_connection)
async def create_connection(*args, **kwargs):
sock = await workers.run_in_thread(_socket.create_connection, *args, **kwargs)
return io.Socket(sock)
, in curio, we should call
sock = await socket.create_connection((host, port), timeout, source_addr)
instead of
sock = await socket.create_connection((host, port), source_addr)
which misses the timeout parameter.
Ah. Got it. Will make a patch for this.
Fixed.
version: 0.9 curio/network.py
failed when source_addr is provided. solution:
Add so._GLOBAL_DEFAULT_TIMEOUT makes it works. It would be a better way if I can write code like this
however, run_in_thread can't take kwargs arguments because it is defined as this: