-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[BUG][Python] async_req=True
doesn't work with asyncio
#5539
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Hello, I'd like second this issue. Because of the bug in how the Is someone working on this issue? Thanks! |
@paololucchino we welcome contributions to fix it. Also worth mentioning the |
It will be nice if the generated code can also pass a callback/error_callback(https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool.apply_async) when |
This removes all the non-async code from the aiohttp generator: * all the methods that should be asynchronous are marked as `async` * the `async_req` parameter is gone; calls are directly awaitables now * the async calls into a thread pool are gone and the thread pool is gone too (now useless) Closes: OpenAPITools#15824 Closes: OpenAPITools#5539 Related: OpenAPITools#763 Related: OpenAPITools#3696
* python: remove non-async code path from the aiohttp generator This removes all the non-async code from the aiohttp generator: * all the methods that should be asynchronous are marked as `async` * the `async_req` parameter is gone; calls are directly awaitables now * the async calls into a thread pool are gone and the thread pool is gone too (now useless) Closes: #15824 Closes: #5539 Related: #763 Related: #3696 * Fix empty line * remove more
Bug Report Checklist
Have you validated the input using an OpenAPI validator (example)?[Optional] Bounty to sponsor the fixDescription
When calling a generated API, the keyword parameter
async_req=True
is supposed to cause the request to be performed asynchronously, i.e. usingmultiprocessing.apply_async
to handle__call_api
instead of directly calling it.However, in the
--library asyncio
target,__call_api
is a coroutine, whichmultiprocessing.apply_async
does not know how to handle.openapi-generator version
4.3.0-SNAPSHOT, pulled as follows:
I don't believe this is a recent regression, the code hasn't been touched since it was introduced in #107 in 2018.
OpenAPI declaration file content or url
https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml
Command line used for generation
Steps to reproduce
After code-gen, create and run the following Python script (which includes workaround for #5538)
Actual output
Notably, the request was never sent.
Expected output
Related issues/PRs
None I'm aware of.
Suggest a fix
Simple fix is to reject the
async_req
keyword in asyncio builds, since we're already "async", even though it's not threaded.A more complex fix would be to have the asyncio target use
concurrent.futures.ThreadPoolExecutor
as the Pool, andasyncio.loop.run_in_executor
instead ofmultiprocessing.apply_async
to run the request in the pool.That will then return an awaitable, which means the API for the caller is the same whether
async_req
isTrue
orFalse
, avoiding theApplyResult
needed in the other library's use ofasync_req
.Note that
works correctly, but it has actually performed the HTTP request on the main thread, and so all it did in the thread pool was create a coroutine object. So it's equivalent to
async_req=False
, but more wasteful.So the open question is, does
async_req
indicate "threaded" or "async"?The text was updated successfully, but these errors were encountered: