Seth Goodman
10/21/2022, 3:50 PMJean Luciano
10/21/2022, 4:12 PMSeth Goodman
10/21/2022, 4:17 PMfrom prefect import task, flow
@task
def my_task():
print("hello")
@flow
def my_flow():
my_task.submit()
my_flow()
@task
def my_task():
print("goodbye")
# error here after trying to redefine task
@flow
def my_flow():
my_task.submit()
my_flow()
Jean Luciano
10/21/2022, 4:48 PMmy_task()
?Seth Goodman
10/21/2022, 4:50 PM@task
def my_task():
print("hello")
@task
def my_task():
print("hello")
# error trigger by second instance
Jean Luciano
10/21/2022, 5:10 PMSeth Goodman
10/21/2022, 5:13 PMRyan Peden
10/21/2022, 9:08 PM@task(name="1")
def my_task():
print("hello")
@task(name="2")
def my_task():
print("hello")
# Prefect remains happy
If you want to get really creative, you could run something like this at the beginning of your interactive Python session:
import uuid
from prefect import task as _task
task = lambda fn, **kwargs: _task(fn, name=str(uuid.uuid4()), **kwargs)
# then, these should work
@task
def my_task():
print("hello")
@task
def my_task():
print("hello")
# Prefect still happy
Disclaimer: you should definitely not do anything like that in production code. But if you just want a quick way to redefine a task a couple of dozen times when you're experimenting in a Python REPL, it should be okay.