For anyone who wonder if this is possible in Python since there are no "real" static variables, yes it is. And it's simpler than you think. All you need to do is to import the variable from another's function module and that's it.
First function:
# Foo
import logging
import azure.functions as func
from src.foo import total
def main(req: func.HttpRequest):
logging.info(id(total))
return func.HttpResponse()
and the second one:
# Bar
import logging
import azure.functions as func
total = 10000
def main(req: func.HttpRequest):
logging.info(id(total))
return func.HttpResponse()
The output from running the app with func start
:
Functions:
foo: [GET,POST] http://localhost:7071/foo
bar: [GET,POST] http://localhost:7071/bar
For detailed output, run func with --verbose flag.
[2022-06-08T21:43:58.463Z] Worker process started and initialized.
[2022-06-08T21:43:59.297Z] Executing 'Functions.foo' (Reason='This function was programmatically called via the host APIs.', Id=d8ef25ff-c913-4351-a3fd-468a252af9e3)
[2022-06-08T21:43:59.353Z] 9792864
[2022-06-08T21:43:59.421Z] Executed 'Functions.foo' (Succeeded, Id=d8ef25ff-c913-4351-a3fd-468a252af9e3, Duration=149ms)
[2022-06-08T21:44:02.633Z] Executing 'Functions.bar' (Reason='This function was programmatically called via the host APIs.', Id=3b2c66a2-7127-4ddd-9ce8-6f8f7c62a4cf)
[2022-06-08T21:44:02.642Z] 9792864
[2022-06-08T21:44:02.644Z] Executed 'Functions.bar' (Succeeded, Id=3b2c66a2-7127-4ddd-9ce8-6f8f7c62a4cf, Duration=14ms)
[2022-06-08T21:44:03.133Z] Host lock lease acquired by instance ID '000000000000000000000000AD81EAAA'.
As you can see, the IDS are the same.