Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
Created October 12, 2021 17:37
Show Gist options
  • Save rochacbruno/adb80404c5749e5c726910480a238a97 to your computer and use it in GitHub Desktop.
Save rochacbruno/adb80404c5749e5c726910480a238a97 to your computer and use it in GitHub Desktop.
better main for python
import atexit
import sys
def main(f):
if f.__module__ == "__main__":
atexit.register(f)
sys.modules['main'] = main # noqa
import main
@main
def my_main_function():
print("This is my main function")
print("this runs first")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment