Can't pickle : attribute lookup class_name on abc failed

后端 未结 1 1434
半阙折子戏
半阙折子戏 2021-01-20 05:50

I\'m getting the above error as I try to create dependencies (subtasks) based on dependency relationship defined in a dictionary (\"cmdList). For instance, \"BDX010\" is a d

相关标签:
1条回答
  • 2021-01-20 06:03

    When creating classes dynamically with a meta-class of ABC, the module becomes abc, and when a worker tries to find the task it goes to the abstract base class module and tries to find it there, but of course it does not exist.

    To solve this, make sure luigi know where to find the code that build the class by manually resetting the __module__ variable.

    Change the line to:

    klass = type(queryKey, (BDX_Task,),{'__module__':__name__})
    

    As far as I know, this is only a problem on Windows.

    Edit: Sorry, stupid of me. Just must also make sure all custom classes gets re-created and added if a new process just imports the module.

    # Run this first outside any other logic so it gets run if someone imports the module:
    for queryKey in cmdList.keys():
        globals()[queryKey] = type(queryKey,(BDX_Task,){'__module__':__name__})
    
    #Then you requires function can look like:
    class BDX_Query_0XX(SQLTask):
    
        # ...
    
        def requires(self):
            for queryKey, (queryCmd, dependQry) in cmdList.items():
                yield globals()[queryKey](
                    acctDate = self.acctDate,
                    ssisDate = self.ssisDate,
                    queryKey = queryKey,
                    queryCmd = queryCmd,
                    runDesc = self.runDesc,  
                    dependQry = dependQry
                )
    
    0 讨论(0)
提交回复
热议问题