When importing the module, main does not get called:
>>> import file
>>> # no output
Note
Note that main gets called immediately, before any code below can be executed.
@entrypoint(__name__)
def main() -> None:
print("-> in main")
print("<- outside")
$ python note.py
-> in main
<- outside
Direct
It is possible to run main directly:
entrypoint(__name__).call(main)
This method allows to take control over where and when the function gets called.
Check
entrypoint also provides is_main function that resembles
the common (and de-facto standard) way of implementing entry points:
from entrypoint import is_main
if is_main(__name__):
print("Hello, world!")
Return
entrypoint expects main functions to not have arguments and return nothing.
Even though this is not checked at runtime, returning from main will cause
type-checkers to error!
Async
entrypoint does not provide any specific functionality to run async functions.
Instead, you can specify, for example, a main function that runs its async_main counterpart:
from async_extensions import run
async def async_main() -> None:
print("Hello, world!")
@entrypoint(__name__)
def main() -> None:
run(async_main())
Implicit
In case an entry point gets created without __name__ given, it is going to attempt
to fetch the module from the main function provided.