Skip to content

Commit

Permalink
Add a workaround for a DNS error where empty grammars are unloadable
Browse files Browse the repository at this point in the history
Dragonfly will now pretend to load and unload grammars with no rules
as a workaround for a DNS error.
  • Loading branch information
drmfinlay committed Jul 19, 2022
1 parent 3c0a531 commit 97322c6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion dragonfly/engines/backend_natlink/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ def _load_grammar(self, grammar):
hypothesis = False

attempt_connect = False

# Return early if the grammar has no rules.
if not rule_names: return wrapper

try:
grammar_object.load(compiled_grammar, all_results, hypothesis)
except self.natlink.NatError as e:
Expand All @@ -246,6 +250,9 @@ def _load_grammar(self, grammar):
raise EngineError("Failed to load grammar %s: %s."
% (grammar, e))

# Grammar has been loaded.
wrapper.loaded = True

# Apply the threading fix if it hasn't been applied yet.
self.apply_threading_fix()

Expand All @@ -256,7 +263,9 @@ def _unload_grammar(self, grammar, wrapper):
""" Unload the given *grammar* from natlink. """
try:
grammar_object = wrapper.grammar_object
grammar_object.unload()
if wrapper.loaded:
grammar_object.unload()
wrapper.loaded = False
grammar_object.setBeginCallback(None)
grammar_object.setResultsCallback(None)
grammar_object.setHypothesisCallback(None)
Expand Down Expand Up @@ -433,6 +442,7 @@ class GrammarWrapper(GrammarWrapperBase):
def __init__(self, grammar, grammar_object, engine, recobs_manager):
GrammarWrapperBase.__init__(self, grammar, engine, recobs_manager)
self.grammar_object = grammar_object
self.loaded = False
self.rule_names = None

def begin_callback(self, module_info):
Expand Down

0 comments on commit 97322c6

Please sign in to comment.