Skip to content

Instantly share code, notes, and snippets.

@ogtega
Created August 2, 2022 06:40
Show Gist options
  • Save ogtega/30752627bbe84dbcd70543783029232f to your computer and use it in GitHub Desktop.
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
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