I am trying to use dask-distributed on my laptop using a LocalCluster, but I have still not found a way to let my application close without raising some warnings or triggering some strange iterations with matplotlib (I am using the tkAgg backend).
For example, if I close both the client and the cluster in this order then tk can not remove in an appropriate way the image from the memory and I get the following error:
Traceback (most recent call last):
File "/opt/Python-3.6.0/lib/python3.6/tkinter/__init__.py", line 3501, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
For example, the following code generates this error:
from time import sleep
import numpy as np
import matplotlib.pyplot as plt
from dask.distributed import Client, LocalCluster
if __name__ == '__main__':
cluster = LocalCluster(
n_workers=2,
processes=True,
threads_per_worker=1
)
client = Client(cluster)
x = np.linspace(0, 1, 100)
y = x * x
plt.plot(x, y)
print('Computation complete! Stopping workers...')
client.close()
sleep(1)
cluster.close()
print('Execution complete!')
The sleep(1)
line makes the problem more likely to appear, as it does not occur at every execution.
Any other combination that I tried to stop the execution (avoid to close the client, avoid to close the cluster, avoid to close both) generates problems with tornado, instead. Usually the following
tornado.application - ERROR - Exception in Future <Future cancelled> after timeout
What is the right combination to stop the local cluster and the client? Am I missing something?
These are the libraries that I am using:
- python 3.[6,7].0
- tornado 5.1.1
- dask 0.20.0
- distributed 1.24.0
- matplotlib 3.0.1
Thank you for your help!