Page 1 of 1

Using sub classes

Posted: Thu Oct 07, 2021 7:40 pm
by ceeceedee
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

Re: Using sub classes

Posted: Sun Oct 10, 2021 1:06 pm
by Giri
ceeceedee wrote: Thu Oct 07, 2021 7:40 pm
How can I get dispynode to recognise enum?
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'.

Re: Using sub classes

Posted: Sun Oct 10, 2021 4:40 pm
by ceeceedee
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