douban / pymesos

A pure python implementation of Mesos scheduler and executor
BSD 3-Clause "New" or "Revised" License
163 stars 88 forks source link

Timeout for connection refused errors? #97

Closed irvinlim closed 6 years ago

irvinlim commented 6 years ago

Hi, is there currently a way for the MesosSchedulerDriver to throw an error when the Mesos master is not available? It seems that it currently gets stuck in an endless loop of "Connection refused" errors once I call driver.run():

framework_1     | 2018-06-06 15:35:26.558|ERROR|Failed to send to ('mesos-master', 5050)
framework_1     | Traceback (most recent call last):
framework_1     |   File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 536, in run
framework_1     |     result = self._run(*self.args, **self.kwargs)
framework_1     |   File "/usr/lib/python2.7/threading.py", line 774, in __bootstrap
framework_1     |     self.__bootstrap_inner()
framework_1     |   File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
framework_1     |     self.run()
framework_1     |   File "/usr/lib/python2.7/threading.py", line 754, in run
framework_1     |     self.__target(*self.__args, **self.__kwargs)
framework_1     |   File "/usr/local/lib/python2.7/dist-packages/pymesos/process.py", line 318, in _run
framework_1     |     if not conn.write():
framework_1     |   File "/usr/local/lib/python2.7/dist-packages/pymesos/process.py", line 76, in write
framework_1     |     logger.exception('Failed to send to %s', self._addr)
framework_1     |   File "/usr/local/lib/python2.7/dist-packages/pymesos/process.py", line 69, in write
framework_1     |     sent = self._sock.send(self._request)
framework_1     |   File "/usr/local/lib/python2.7/dist-packages/gevent/_socket2.py", line 323, in send
framework_1     |     return sock.send(data, flags)
framework_1     | error: [Errno 111] Connection refused

I would like a way to catch the exception and handle it accordingly. Otherwise, something like a timeout would be good as well.