Any advice on these errors? Seeing this with Flas...
# ask-community
s
Any advice on these errors? Seeing this with Flask + Prefect 2.6.8 running in K8's on GCP. Doesn't seem to affect anything, just gives this weird error in the logs:
Copy code
Traceback (most recent call last):
ERROR | asyncio - Task exception was never retrieved
"future: <Task finished name='Task-36' coro=<<async_generator_athrow without __name__>()> exception=KeyError(139836083032272)>"
File "/usr/local/lib/python3.8/dist-packages/prefect/utilities/asyncutils.py", line 263, in on_shutdown yield
GeneratorExit
During handling of the above exception, another exception occurred:
File "/usr/local/lib/python3.8/dist-packages/prefect/utilities/asyncutils.py", line 267, in on_shutdown
    EVENT_LOOP_GC_REFS.pop(key)
KeyError: 139836083032272"
1
b
Hello Sean, looks like we may have a GitHub issue open that somewhat mirrors the behavior you're seeing here. This is currently being investigated.
s
OK good to know - I'll keep my eye on this for a fix - thanks so much!
🙌 1
z
Hey! Would you mind throwing the traceback and any additional details into https://github.com/PrefectHQ/prefect/issues/7709
upvote 1
gratitude thank you 1
This is related to our cleanup of async database engines, which is really sketchy because Python does not actually provide a way to perform cleanup on event loop closure.
Are you running your API separately from your flows? ie with
prefect orion start
?
s
Gotcha. Ok so I think unfortunately what I posted above is all the traceback I'm seeing for this... The API is getting created by Flask, I'm not calling
prefect orion start
anywhere.
Copy code
import os
import json
from flask import Flask, request
import logging
import traceback
from prefect.orion.schemas.states import StateType

app = Flask(__name__)

#################################################
#
#  Flask routes
#
#################################################
@app.route('/', methods=['POST'])
def default_route_main():

    force_exception = location_success = False
    try:
        # Run flow
        flow_state = my_flow(return_state=True)

        force_exception = flow_state.result()
        flow_success = flow_state.type == (StateType.COMPLETED)
This is the basics of the Flask wrapper
z
If you point to a existing API, the database connection won’t be managed inside of Flask which should be more stable
s
Gotcha...happy to give that a shot. Sorry for the dumb question - but do you have an example somewhere I could look at for how to do that?
z
Basically you run
prefect orion start
then set the
PREFECT_API_URL
to localhost in your config.. let me see
s
Thank you!
z
For Kubernetes, I think there are better examples
👀 1
Like, you can run this on another pod.
s
Ok yeah - that will help - thanks
z
👍 also
prefect kubernetes manifest orion