Commit 4cf74094 authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

make IPyResult wait() and abort() interruptible

parent adda5241
......@@ -146,7 +146,9 @@ class IPyResult(object):
msg_ids = [i.msg_ids[0] for i in self._running_jobs]
self.ipycluster.abort(msg_ids)
self.ipycluster.spin()
[i.wait() for i in self._running_jobs]
for i in self._running_jobs:
while not i.wait(1):
continue
self.data += [i.get() for i in self._running_jobs if i.successful()]
def dump(self, filename, method='raise'):
......@@ -234,9 +236,10 @@ class IPyResult(object):
def wait(self, timeout=None):
"""Wait for calculation to complete or timeout."""
if timeout == 0:
timeout += 1e-2 # Necessary to account for python overhead.
timeout = 1e-2 # Necessary to account for python overhead.
if timeout is None or timeout < 0:
self.finished.wait()
while not self.finished.wait(1):
continue
self.thread.join()
self._pop_queue()
[j.wait() for j in self._running_jobs]
......@@ -244,13 +247,16 @@ class IPyResult(object):
return True
else:
end_time = time.time() + timeout
if not self.finished.wait(timeout):
while (end_time - time.time() > 1) and not self.finished.wait(1):
continue
if not self.finished.wait(end_time - time.time()):
return False
self.thread.join()
self._pop_queue()
for i in self._running_jobs:
if not i.wait(end_time - time.time()):
return False
self.update()
return True
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment