Skip to content

AttributeError: type object '...' has no attribute '_io_loop' in Actor constructed without a default client #6477

@graingert

Description

@graingert

see dask/dask-jobqueue#552
when running an actor with a client constructed with Client(set_as_default=False) attribute lookup fails with an AttributeError:

import sys
import distributed

class Counter:
    """ A simple class to manage an incrementing counter """
    n = 0

    def __init__(self):
        self.n = 0

    def increment(self):
        self.n += 1
        return self.n

    def add(self, x):
        self.n += x
        return self.n

def main():
    with distributed.Client(set_as_default=False) as client:
        counter = client.submit(Counter, actor=True).result()
        counter.add(1)
        print(f"{counter.n=}")

if __name__ == "__main__":
    sys.exit(main())
Traceback (most recent call last):
  File "/home/graingert/projects/distributed/foo.py", line 26, in <module>
    sys.exit(main())
  File "/home/graingert/projects/distributed/foo.py", line 22, in main
    counter.add(1)
  File "/home/graingert/projects/distributed/distributed/actor.py", line 215, in func
    actor_future = ActorFuture(io_loop=self._io_loop)
  File "/home/graingert/projects/distributed/distributed/actor.py", line 190, in __getattr__
    attr = getattr(self._cls, key)
AttributeError: type object 'Counter' has no attribute '_io_loop'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions