https://prefect.io logo
#prefect-community
Title
# prefect-community
o

Ofir

08/26/2022, 2:38 PM
Prefect’s documentation says the following:
Create a flow as a context manager and call your tasks on each other as if they were regular functions. Prefect will track each function call and build up a computational graph that represents your workflow. Critically, no tasks are actually executed at this time.
1
z

Zanie

08/26/2022, 3:07 PM
Yeah, calling the tasks here just signals that they should be added to the DAG.
o

Ofir

08/26/2022, 3:08 PM
It’s interesting from implementation perspective how is it achieved
It’s like changing Python’s core flow, would never imagined that Python is that flexible and allows to hook post/pre any function call
r

Ryan Peden

08/26/2022, 3:29 PM
Everything called inside the context manager is a Task (whether created imperatively or using the
@task
decorator), and Task is Callable (i.e., it implements
__call__
), which makes it easy to do anything you'd like before or after calling the original function.
o

Ofir

08/26/2022, 3:31 PM
Gotcha, thanks!
r

Ryan Peden

08/26/2022, 3:32 PM
Keep in mind that the docs page you linked is for Prefect 1. If you're just starting with Prefect as you mentioned in your previous thread, you'll want to use Prefect 2, which doesn't use a flow context manager - instead, you decorate a function with
@flow
.
🙏 1
o

Ofir

08/26/2022, 3:38 PM
Thanks @Ryan Peden for the comment. Is it mature enough like 1.0? I am going to run this in production very soon
r

Ryan Peden

08/26/2022, 3:43 PM
Yes - many others are happily running Prefect 2 in production 😄
👍 1
o

Ofir

08/26/2022, 3:45 PM
so I guess 1.0 is deprecated/EOL’d soon and most of the efforts of the core are focused on Prefect 2.0
r

Ryan Peden

08/26/2022, 3:49 PM
Prefect 1 is still maintained right now, but Prefect 2 is the best choice for new projects.
o

Ofir

08/26/2022, 3:50 PM
Thanks a lot Ryan.
r

Ryan Peden

08/26/2022, 3:52 PM
You're welcome! 😄