Created
April 9, 2021 05:51
-
-
Save linw1995/bb5e9e378e2f3dcb5820fd2dffeead0e to your computer and use it in GitHub Desktop.
Click with async command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Standard Library | |
import asyncio | |
import functools | |
# Third Party Library | |
import click | |
def async_command(coro_func): | |
@functools.wraps(coro_func) | |
def sync_func(*args, **kwargs): | |
return asyncio.run(coro_func(*args, **kwargs)) | |
return sync_func | |
@click.command() | |
@async_command | |
async def hello(): | |
print("hello world") | |
if __name__ == "__main__": | |
hello() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment