You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way I understand it, the functions framework imports the modules where you’ve defined decorators (e.g. @https_fn.on_request, @firestore_fn.on_document_written), builds a small Flask app, then exposes these functions. This means there’s no “main script” entrypoint and so code in a global scope outside of a function will not get executed.
My specific use case is that I want to execute some additional initialisation code before spinning up the function when I start it
Specifically I would like to optionally attach a debugger when running locally with a parameter flag set so something like:
ENABLE_DEBUGGER = BoolParam("ENABLE_DEBUGGER", default=False) if ENABLE_DEBUGGER.value: import debugpy debugpy.listen(("127.0.0.1", 5678)) print("⚡ debugpy listening on 127.0.0.1:", "5678")
However, I cannot find anywhere I can put this code to ensure it is executed on startup. I have tried putting it at the very top of the main.py, putting in an __init__.py, putting it in an @init function, but nothing seems to work. The only way I can get this to work is by putting it inside a function itself. However, while this issue still exists: #6838, I would like to formalise this method across my codebases to allow for local debugging if necessary and plotting this around inside real function code isn't desirable.
As well as the above it would be good if you could do things like initialise log level logging.basicConfig(level=logging.INFO) before serving the functions.
Does anyone know if anything likethis is possible?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
The way I understand it, the functions framework imports the modules where you’ve defined decorators (e.g. @https_fn.on_request, @firestore_fn.on_document_written), builds a small Flask app, then exposes these functions. This means there’s no “main script” entrypoint and so code in a global scope outside of a function will not get executed.
My specific use case is that I want to execute some additional initialisation code before spinning up the function when I start it
Specifically I would like to optionally attach a debugger when running locally with a parameter flag set so something like:
However, I cannot find anywhere I can put this code to ensure it is executed on startup. I have tried putting it at the very top of the
main.py, putting in an__init__.py, putting it in an@initfunction, but nothing seems to work. The only way I can get this to work is by putting it inside a function itself. However, while this issue still exists: #6838, I would like to formalise this method across my codebases to allow for local debugging if necessary and plotting this around inside real function code isn't desirable.As well as the above it would be good if you could do things like initialise log level
logging.basicConfig(level=logging.INFO)before serving the functions.Does anyone know if anything likethis is possible?
Beta Was this translation helpful? Give feedback.
All reactions