python - 在Python中的数据类上使用prefect 2.0流程

标签 python python-3.x prefect

我正在尝试用完美的流程包装一个类,该流程目前通过看起来像这样的类来工作:

class Algorightm:

   @task
   def do_first(self, something):
      ....
  
   @task
   def do_second(self, something_else):
      ....

   @flow
   def start_flow(self):
      do_first(..)
      do_second(..)

通常情况下,这可以正常工作,如果我将其分解为外部函数,则流程可以正常运行,这意味着如果我只是在类之外使用它,则可以根据需要工作:
这会起作用:

   @task
   def do_first(self, something):
      ....
  
   @task
   def do_second(self, something_else):
      ....

   @flow
   def start_flow(self):
      do_first(..)
      do_second(..)

但是当在类中使用它时,它会给我一个递归错误。 问题是,prefect是否支持在类中使用It's flow?我在文档中找不到任何有关它的信息

最佳答案

Prefect 流程必须是函数而不是类方法。否则,您将无法为其创建部署。但是,您可以在该函数中调用您的类,Prefect 甚至支持使用 Pydantic 进行参数验证(如果您使用此类来获取 pydantic 模型样式验证,则共享此 pydantic 信息)

关于python - 在Python中的数据类上使用prefect 2.0流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74168859/

相关文章:

python - 从列表创建的表未显示所有元素

Python 3 安装位置

python - 无法使用 python 解析 XML 文件。想要从 python 文件中删除一行。帮我删除该行

prefect - 如何使用 prefect "mapped"并行化嵌套循环

python - 如何使用 Prefect 在 AKS 上部署 Kubernetes 作业

python - 如何在失败时恢复 Prefect 流程而不必重新运行整个流程?

python - 在类之外使用 wxPython 元素?

python - 在文件中搜索小时数的最佳方法

python - 前 N 个最相关列的平均值的 DataFrame

Python列表——去重和添加子列表元素