mirror of
https://github.com/hypervortex/VH-Bombsquad-Modded-Server-Files
synced 2025-10-16 12:02:51 +00:00
Delete nbstreamreader.py
This commit is contained in:
parent
097d093c01
commit
bc49523c99
1 changed files with 0 additions and 39 deletions
|
|
@ -1,39 +0,0 @@
|
|||
from threading import Thread
|
||||
from queue import Queue, Empty
|
||||
|
||||
class NonBlockingStreamReader:
|
||||
|
||||
def __init__(self, stream):
|
||||
'''
|
||||
stream: the stream to read from.
|
||||
Usually a process' stdout or stderr.
|
||||
'''
|
||||
|
||||
self._s = stream
|
||||
self._q = Queue()
|
||||
|
||||
def _populateQueue(stream, queue):
|
||||
'''
|
||||
Collect lines from 'stream' and put them in 'quque'.
|
||||
'''
|
||||
|
||||
while True:
|
||||
line = stream.readline()
|
||||
if line:
|
||||
queue.put(line)
|
||||
else:
|
||||
raise UnexpectedEndOfStream
|
||||
|
||||
self._t = Thread(target = _populateQueue,
|
||||
args = (self._s, self._q))
|
||||
self._t.daemon = True
|
||||
self._t.start() #start collecting lines from the stream
|
||||
|
||||
def readline(self, timeout = None):
|
||||
try:
|
||||
return self._q.get(block = timeout is not None,
|
||||
timeout = timeout)
|
||||
except Empty:
|
||||
return None
|
||||
|
||||
class UnexpectedEndOfStream(Exception): pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue