Permalink
Browse files

Try to avoid server hangs.

It seems that the most common cause (if not the only cause) of the dictation server hangs is natlink.natConnect() hanging. Previously, in an effort to coalesce multiple connections to natlink across a single server session, we always connected to natlink upon connection to the server. This was hanging, and in most cases, we did not even need to use natlink in that server session.

So, instead, connect lazily to natlink.
  • Loading branch information...
1 parent ce7ae4f commit d30d61d4cc3bfc4191b797924869934715ac153b @nriley committed Jul 14, 2015
Showing with 15 additions and 4 deletions.
  1. +15 −4 dictation_server.pyw
View
@@ -62,20 +62,31 @@ def set_taskbar_autohide(on):
CLIPBOARD_RTF = win32clipboard.RegisterClipboardFormat('Rich Text Format')
class DragonService(rpyc.Service):
+ __slots__ = ('natlink_connected',)
+
should_keep_serving = True
def on_connect(self):
- natlink.natConnect(True)
+ self.natlink_connected = False
def on_disconnect(self):
- natlink.natDisconnect()
+ if self.natlink_connected:
+ natlink.natDisconnect()
+
+ def natlink(self):
+ if not self.natlink_connected:
+ logging.info('connecting...')
+ natlink.natConnect(True)
+ logging.info('connected')
+ self.natlink_connected = True
+ return natlink
def exposed_get_mic_state(self):
- return natlink.getMicState()
+ return self.natlink().getMicState()
def exposed_set_mic_state(self, state):
try:
- natlink.setMicState(state)
+ self.natlink().setMicState(state)
except natlink.NatError:
if state != 'on':
raise

0 comments on commit d30d61d

Please sign in to comment.