On using Asyncio #864
Answered
by
YuriiMotov
BhuwanPandey
asked this question in
Questions
-
First Check
Commit to Help
Example CodeHey there,
I have file abcd.py where code looks like
from asyncio import run as aiorun
import typer
app = typer.Typer()
async def async_process():
print("hello I am async")
@app.command()
def hello():
print("I am Hello")
@app.command()
def async_handle():
aiorun(async_process())
if __name__ == "__main__":
app()
when I run
python abcd.py async_handle it run successfully but
but when I changed code to
from asyncio import run as aiorun
import typer
app = typer.Typer()
async def async_process():
print("hello I am async")
@app.command()
def async_handle():
aiorun(async_process())
if __name__ == "__main__":
app()
when i run abcd.py async_handle, it say
Got unexpected extra argument (async-handle) Description.. Operating SystemWindows Operating System DetailsNo response Typer Version0.12.3 Python Version3.11 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
YuriiMotov
Sep 15, 2025
Replies: 1 comment
-
This is because if you have only one command, Typer makes some optimizations and you don't need to specify command to call it. So, it treats The solution is to add a callback as described here: https://typer.tiangolo.com/tutorial/commands/one-or-multiple/#one-command-and-one-callback from asyncio import run as aiorun
import typer
app = typer.Typer()
async def async_process():
print("hello I am async")
@app.command()
def async_handle():
aiorun(async_process())
@app.callback()
def callback():
pass
if __name__ == "__main__":
app() And, your command name will actually be Try it:
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YuriiMotov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is because if you have only one command, Typer makes some optimizations and you don't need to specify command to call it. So, it treats
async_handle
inabcd.py async_handle
as an argument, thus it shows that error.The solution is to add a callback as described here: https://typer.tiangolo.com/tutorial/commands/one-or-multiple/#one-command-and-one-callback
And, your command name will actually be
async-handle
(with das…