-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add support for async objects in CLI
#517
Comments
I am not sure that this can be fixed. Classes are instantiated before calling the function. And being required to only be run inside an async function is very specific to Not tested, but how about: async def cli():
CLI(main)
if __name__ == "__main__":
await cli() Or maybe instead: async def main(producer: Callable[[], aiokafka.AIOKafkaProducer]) -> None:
producer_instance = producer()
... Side note. I merged a pull request fixing |
If I use the first option, then I get Also, I found that I was running the code using
|
I think it is possible with |
I implemented support for async functions in #531. But note what I mentioned before, import asyncio
from typing import Callable
from jsonargparse import CLI
from aiokafka import AIOKafkaProducer
async def main(producer: Callable[[], AIOKafkaProducer]):
producer_instance = producer()
print(producer_instance)
await asyncio.sleep(0)
if __name__ == "__main__":
CLI(main) |
🚀 Feature request
Add support for objects that require asynchronous context for their creation.
Motivation
Currently I cannot instantiate objects like
aiokafka.AIOKafkaProducer
. For example:In
main.py
:In
config.yaml
:In terminal:
Gives error:
Pitch
The above code should runs without errors.
Alternatives
The text was updated successfully, but these errors were encountered: