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'
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: