Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend specific options don't appear to be used #643

Closed
2 tasks done
DaGenix opened this issue Nov 27, 2023 · 7 comments · Fixed by #647
Closed
2 tasks done

Backend specific options don't appear to be used #643

DaGenix opened this issue Nov 27, 2023 · 7 comments · Fixed by #647
Labels
bug Something isn't working

Comments

@DaGenix
Copy link

DaGenix commented Nov 27, 2023

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

AnyIO version

4.1.0

Python version

3.11

What happened?

As best as I can tell, the backend specific options for both the asyncio and trio options aren't being used

def run(
cls,
func: Callable[..., Awaitable[T_Retval]],
args: tuple,
kwargs: dict[str, Any],
options: dict[str, Any],
) -> T_Retval:
@wraps(func)
async def wrapper() -> T_Retval:
task = cast(asyncio.Task, current_task())
task.set_name(get_callable_name(func))
_task_states[task] = TaskState(None, None)
try:
return await func(*args)
finally:
del _task_states[task]
debug = options.get("debug", False)
options.get("loop_factory", None)
options.get("use_uvloop", False)
return native_run(wrapper(), debug=debug)

def run(
cls,
func: Callable[..., Awaitable[T_Retval]],
args: tuple,
kwargs: dict[str, Any],
options: dict[str, Any],
) -> T_Retval:
return trio.run(func, *args)

How can we reproduce the bug?

I'm sorry if I'm missing something, but the backend options don't appear to be used, except for debug for asyncio. I don't have a test case, however, so, I apologize again if I'm not seeing how the options are getting applied.

@DaGenix DaGenix added the bug Something isn't working label Nov 27, 2023
@agronholm
Copy link
Owner

What backend options are you trying to pass?

@DaGenix
Copy link
Author

DaGenix commented Nov 27, 2023

I was looking into enabling the uvloop option and was overall interested in which options where available. But, looking at the code, it appeared that the options weren't being used.

@agronholm
Copy link
Owner

On the asyncio backend, the debug, loop_factory and use_uvloop options are used, as indicated in the code you pasted. What other options are you looking to pass?

@DaGenix
Copy link
Author

DaGenix commented Nov 29, 2023

@agronholm In the code I posted, the only mention of use_uvloop is:

     options.get("use_uvloop", False) 

Which fetches it from the options dictionary, but then does nothing with the value.

I'm not super familiar with the anyio code, however, so, I apologize if its being used somewhere else.

However, I tried the following test program:

import anyio
import asyncio


async def inside_asyncio() -> None:
    print(asyncio.get_running_loop())


anyio.run(inside_asyncio, backend_options={"use_uvloop": True})

When I run the above with anyio 3.7.1, it prints out:

<uvloop.Loop running=True closed=False debug=False>

However, when I run it with 4.1.0, it prints out:

<_UnixSelectorEventLoop running=True closed=False debug=False>

@agronholm
Copy link
Owner

Oh wow, I didn't see that. So apparently while they are used for the test runner, they're ignored for anyio.run(). This is a big oversight. I'll get this sorted out for the next release.

@agronholm
Copy link
Owner

@DaGenix I trust that the linked PR fixes the issue? Would you mind taking a peek?

@DaGenix
Copy link
Author

DaGenix commented Dec 9, 2023

@agronholm cool. that looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants