Using sub classes

Questions, issues regarding dispy / pycos

Moderator: admin

Post Reply
ceeceedee
Posts: 2
Joined: Thu Oct 07, 2021 7:26 pm

Using sub classes

Post 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
Giri
Site Admin
Posts: 58
Joined: Sun Dec 27, 2020 5:35 pm

Re: Using sub classes

Post 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'.
ceeceedee
Posts: 2
Joined: Thu Oct 07, 2021 7:26 pm

Re: Using sub classes

Post 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
Post Reply