Skip to content

Commit e8ad7fb

Browse files
committed
Consume/ignore the rest of the server output
Without this, the server will end up hanging due to the buffer filling up. This fixes jxmorris12#16.
1 parent a7b6ede commit e8ad7fb

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎language_check/__init__.py‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import re
2727
import socket
2828
import sys
29+
import threading
2930
import urllib.parse
3031
import urllib.request
3132
from collections import OrderedDict
@@ -346,8 +347,8 @@ def _start_server(cls):
346347
if match:
347348
port = int(match.group(1))
348349
if port != cls._port:
349-
raise Error('requested port {}, but got {}'
350-
.format(cls._port, port))
350+
raise Error('requested port {}, but got {}'.format(
351+
cls._port, port))
351352
break
352353
if not match:
353354
cls._terminate_server()
@@ -359,6 +360,19 @@ def _start_server(cls):
359360
port = int(match.group(1))
360361
if port != cls._port:
361362
raise Error(err_msg)
363+
364+
def consume():
365+
"""Consume/ignore the rest of the server output.
366+
367+
Without this, the server will end up hanging due to the buffer
368+
filling up.
369+
370+
"""
371+
while cls._server and cls._server.stdout.readline():
372+
pass
373+
cls._thread = threading.Thread(target=consume)
374+
cls._thread.daemon = True
375+
cls._thread.start()
362376
if not cls._server:
363377
# Couldn't start the server, so maybe there is already one running.
364378
params = {'language': FAILSAFE_LANGUAGE, 'text': ''}

0 commit comments

Comments
 (0)