Created
August 2, 2022 06:40
-
-
Save ogtega/30752627bbe84dbcd70543783029232f to your computer and use it in GitHub Desktop.
A Python decorator to start an application regardless if it is async or not
This file contains hidden or 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
def startup(): | |
def decorator(func: typing.Callable): | |
if __name__ == "__main__": | |
if asyncio.iscoroutinefunction(func): | |
asyncio.run(func()) | |
else: | |
func() | |
return func | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment