Tejas Shah
02/16/2024, 10:05 PM<frozen runpy>:128: RuntimeWarning: 'prefect.engine' found in sys.modules after import of package 'prefect', but prior to execution of 'prefect.engine'; this may result in unpredictable behaviour
Marvin
02/16/2024, 10:06 PMprefect.engine
was already loaded ("found in sys.modules") at the time when the package prefect
was imported, but before any code in the prefect.engine
module had been run.
This situation can occur if:
1. A module is being imported in a non-standard way, which can happen if import hooks or custom importers are being used that manipulate sys.modules
directly.
2. There's a circular import, where two modules are importing each other, or there are import loops within a package.
It's generally a sign of something unseemly happening with the import system, which Python would like to warn you about, because it could lead to unpredictable behavior. The module may not be in the state that you expect when the execution of the package begins, leading to potential errors or incorrect behavior.
If you're just using Python scripts and not doing anything particularly fancy with import hooks or the sort, then it might be a sign of an actual issue within the prefect
package or the way it's being used.
To potentially clear up the issue:
1. Check for circular imports in your codebase.
2. Make sure you aren't manipulating sys.modules
yourself in some unorthodox manner.
3. Try to import prefect
at the start of your script if it's not the first import.
If you're still experiencing this issue or it's causing more substantial problems, let me know, and I can look up any known issues or further information on the matter. Would you like me to do that?Tejas Shah
02/16/2024, 10:07 PMMarvin
02/16/2024, 10:07 PMRuntimeWarning
you are experiencing. Here are the brief details:
1. Work queue concurrency not always respected by agent: An issue was reported (#10771) where the work queue concurrency limit was not respected by agents when no work pool is specified. The RuntimeWarning
associated with prefect.engine
was observed in the logs when starting the agent without specifying a work pool.
2. runpy
engine import 'unpredictable behaviour' warnings: Another similar issue (#7869) was logged when running a job where the same warning related to prefect.engine
was observed.
3. ModuleNotFoundError when simultaneously running deployed flows using custom image: There was an issue (#8337) where running multiple flows that use the prefect-dbt
package caused a ModuleNotFoundError
for the second flow that was launched. The RuntimeWarning
related to prefect.engine
appeared in the cluster logs at the same time as the error.
These issues indicate that the warning could possibly be related to agent behavior with work queues, or it might occur when multiple flows are being managed and run with particular package dependencies. Since the warning suggests something about the import system might be amiss, it could be a symptom rather than the cause of these issues.
You may want to check the discussions or updates on these issues for potential resolutions or workarounds. If your situation doesn't resonate with these cases, providing more context or digging deeper into the specifics of your Prefect version, your flows, and how you run them could be necessary to isolate the cause.Jeff Hale
02/16/2024, 10:11 PMTejas Shah
02/16/2024, 10:14 PMJeff Hale
02/16/2024, 10:14 PMTejas Shah
02/16/2024, 10:14 PMTejas Shah
02/16/2024, 10:15 PMJeff Hale
02/16/2024, 10:16 PM