I am a dispy newbie and am trying to distribute an existing application using dispy but I am having problems using class I have created which is a subclass of enum.Enum
dispynode.py falls over with the error...
NameError: name 'enum' is not defined
...when encountering the line:
class MyEnumSubclass(enum.Enum):
In my standard (non dispy) code the module including this line has...
import enum
...before the MyEnumSubclass definition.
How can I get dispynode to recognise enum?
CCD
Using sub classes
Moderator: admin
-
- Site Admin
- Posts: 58
- Joined: Sun Dec 27, 2020 5:35 pm
Re: Using sub classes
dispynode is remote and not aware of classes, libraries used in client programs. You can use 'depends' feature to send dependencies to nodes. For example, you can send 'enum' library (module) with
cluster = dispy.JobCluster(compute, depends=[enum])
Then load enum in computations with 'import enum'.
-
- Posts: 2
- Joined: Thu Oct 07, 2021 7:26 pm
Re: Using sub classes
Hello,
Thank you for you reply.
I had tried your suggestion but it did not help because I was subclassing Enum and the import statement (from enum import Enum) was at the start of my module and thus was not getting copied into the compute code. My class definition was making it to the compute code but it was throwing errors at the line...
class MyEnum(Enum):
...because Enum had not yet been imported.
In the end I fixed the problem by including the module containing MyEnum in the depends list...
cluster = dispy.JobCluster(compute, depends=['c:\mymodules\myenum.py'])
...rather than just including MyEnum...
cluster = dispy.JobCluster(compute, depends=[MyEnum])
CCD
Thank you for you reply.
I had tried your suggestion but it did not help because I was subclassing Enum and the import statement (from enum import Enum) was at the start of my module and thus was not getting copied into the compute code. My class definition was making it to the compute code but it was throwing errors at the line...
class MyEnum(Enum):
...because Enum had not yet been imported.
In the end I fixed the problem by including the module containing MyEnum in the depends list...
cluster = dispy.JobCluster(compute, depends=['c:\mymodules\myenum.py'])
...rather than just including MyEnum...
cluster = dispy.JobCluster(compute, depends=[MyEnum])
CCD