Skip to content

Commit

Permalink
An attempt at solving the redoubtable "subprocess busy" bug. I don't …
Browse files Browse the repository at this point in the history
…think it works though.
  • Loading branch information
BrenBarn committed Oct 13, 2016
1 parent d288e7e commit 1c079ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
25 changes: 21 additions & 4 deletions dreampielib/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def call_subp_noblock(self, funcname, *args):
return self.subp.recv_object()
else:
self._n_unclaimed_results += 1
raise TimeoutError
raise TimeoutError(while_receiving=True)

def call_subp_catch(self, funcname, *args):
"""
Expand All @@ -888,6 +888,23 @@ def call_subp_catch(self, funcname, *args):
except TimeoutError:
return None

def _call_subp_catch_internal(self, funcname, *args):
"""
We make a non-blocking call, but if a timeout is raised while waiting
for the result, we patch it up by decrementing _n_unclaimed_results.
This MIGHT fix a nasty bug whereby if the timeout is raised while
we wait for attribute completion, we get "stuck" thinking we have to
wait for a computation result that will never come.
"""
if self.is_executing:
return None
try:
return self.call_subp_noblock(funcname, *args)
except TimeoutError as e:
if e.while_receiving:
self._n_unclaimed_results -= 1
return None

def on_object_recv(self, obj):
if self._n_unclaimed_results:
self._n_unclaimed_results -= 1
Expand Down Expand Up @@ -1220,13 +1237,13 @@ def on_show_completions(self, _widget):
self.autocomplete.show_completions(is_auto=False, complete=False)

def complete_dict_keys(self, expr):
return self.call_subp_catch(u'complete_dict_keys', expr)
return self._call_subp_catch_internal(u'complete_dict_keys', expr)

def complete_attributes(self, expr):
return self.call_subp_catch(u'complete_attributes', expr)
return self._call_subp_catch_internal(u'complete_attributes', expr)

def complete_firstlevels(self):
return self.call_subp_catch(u'complete_firstlevels')
return self._call_subp_catch_internal(u'complete_firstlevels')

def get_func_args(self, expr):
return self.call_subp_catch(u'get_func_args', expr)
Expand Down
3 changes: 2 additions & 1 deletion dreampielib/gui/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ def get_text(textbuffer, *args):
return textbuffer.get_text(*args).decode('utf8')

class TimeoutError(Exception):
pass
def __init__(self, while_receiving=False):
self.while_receiving = while_receiving

0 comments on commit 1c079ba

Please sign in to comment.