https://prefect.io logo
a

Anh Nguyen

09/23/2021, 1:53 AM
Could you tell me how to invoke the class that is called between tasks ?
k

Kevin Kho

09/23/2021, 2:38 AM
Hey @Anh Nguyen, not sure what you are asking. Are you saying there is a class that you need in tasks? Similar to this?
Copy code
cls = MyClass()

@task
def task_A():
    cls.do_something()
    return
a

Anh Nguyen

09/23/2021, 1:20 PM
Thanks Bro! I has a questions: How to make a connection which is used in many task? Plz, Give me the example for that
k

Kevin Kho

09/23/2021, 2:29 PM
This is harder because connections send to be unserializeable and Dask uses
cloudpickle
to send stuff to the workers. So the limitations here are that you need to use LocalExecutor or LocalDaskExecutor (with threads) and then:
Copy code
cls = MyClass()

@task
def task_A():
    cls.do_something()
    return

with Flow(...) as flow:
     task_A.map([1,2,3])
but this requires your flow to be stored as a script because the default behavior is to serialize your Flow and these connections cant be serialized