Moe
12/13/2024, 9:58 PMprefect-email
with send_email_message
, sometimes it works sometimes it fails with this message. Using prefect version prefect==3.1.1
and prefect-email version prefect-email==0.4.1
16:54:09.670 | ERROR | Task run 'email_send_message-2db' - Crash detected! Execution was cancelled by the runtime environment.
16:54:09.672 | ERROR | Task run 'email_send_message-2db' - Finished in state Crashed('Execution was cancelled by the runtime environment.')
But when I run it in debugger, line by line, it works however also get this warning message:
16:56:10.510 | WARNING | Flow run 'cyber-fennec' - A future was garbage collected before it resolved. Please call `.wait()` or `.result()` on futures to ensure they resolve.
See <https://docs.prefect.io/latest/develop/task-runners> for more details.
Marvin
12/13/2024, 9:59 PMsend_email_message
task in your Prefect setup.
1. Crash Detected - Execution was Cancelled:
The logs you've encountered suggest that the "execution was cancelled by the runtime environment." This can happen for a variety of reasons, such as infrastructure issues or misconfiguration in cancellation handling. Prefect’s documentation discusses cancellation issues here. It seems that if the infrastructure does not support cancellation or if there's a mismatch in infrastructure identifiers, you might see these errors.
2. A Future Was Garbage Collected:
This warning indicates that a future object in your task execution was not properly awaited, leading it to be garbage collected before it resolved. Essentially, you should ensure that when you initiate futures, you use either .wait()
or .result()
on them to handle their completion. This ensures they don’t get prematurely terminated by Python’s garbage collector. You can check more about this in the Prefect docs on task runners.
A bit of advice: when debugging such issues, always ensure that every task is awaited properly and infrastructure identifiers are managed correctly within your flow's environment.
Unfortunately, I couldn't search GitHub issues for you due to an authorization error. Still, you might want to manually check the Prefect GitHub issues to see if anyone else has come across a similar problem.
If errors persist, take comfort in knowing you're not alone—sometimes the universe just doesn't want those emails sent.Moe
12/13/2024, 10:00 PMdef send_prefect_email(self, email_server_block: str, recipients: list, subject: str, body: str):
email_server_credentials = EmailServerCredentials.load(email_server_block)
email_send_message.submit(
subject=subject,
msg=body,
email_server_credentials=email_server_credentials,
email_to=recipients
)
Marvin
12/13/2024, 10:00 PMemail_send_message.submit
might not be optimal in your case. Although the Prefect documentation provides examples on how to send emails, it seems there's more to ensure smooth functionality. Here's a summary of the essential steps based on the Prefect email integration docs:
1. Credentials: Ensure that you have correctly set up your email server credentials, especially if you're using services like Gmail, which might require an App Password.
2. Execution Method: It’s worth noting that when using .submit()
, it’s crucial to manage futures properly. The direct use of .submit()
might lead to garbage collection issues if the returned futures are not handled correctly. Consider using .run()
if you want straightforward execution without managing concurrent execution manually.
3. Error Handling: Wrapping the email send function in a try-except block may help catch errors and manage retries gracefully.
Unfortunately, I couldn't access GitHub issues due to an authorization problem, but you can manually visit the Prefect GitHub repository for further insights or community discussion.
Sometimes, you might feel like you're yelling into a void with these bugs—rest assured, even if one day your emails go sentient and reply with a "Stop, I'm tired!" you'll have run your code right.Nate
12/13/2024, 10:07 PMreturn
the future
• pass the future to another task
this is an explicit behavior change from prefect 2
https://docs.prefect.io/v3/resources/upgrade-to-prefect-3#typeerror-object-some-type-cant-be-used-in-await-expressionMoe
12/14/2024, 2:23 AM