Added bucketing based on file type (text/binary) and batching to reduce

server calls.
This commit is contained in:
unknown 2015-05-12 14:47:18 -06:00
parent 49153babed
commit c32c0bfbd1
2 changed files with 156 additions and 98 deletions

View file

@ -4,7 +4,7 @@
# python_version : 2.7.6 and 3.4.0
# =================================
import datetime, inspect, marshal, multiprocessing, optparse, os, re, stat, subprocess, sys, threading
import datetime, inspect, itertools, marshal, multiprocessing, optparse, os, re, stat, subprocess, sys, threading
# trying ntpath, need to test on linux
import ntpath
@ -297,19 +297,19 @@ class Console( threading.Thread ):
self.auto_flush_time = auto_flush_time * 1000 if auto_flush_time is not None else -1
self.shutting_down = False
def write( self, data, pid = None ):
self.queue.put( ( Console.MSG.WRITE, pid if pid is not None else os.getpid(), data ) )
def write( self, data ):
self.queue.put( ( Console.MSG.WRITE, threading.current_thread().ident, data ) )
def writeflush( self, data, pid = None ):
pid = pid if pid is not None else os.getpid()
def writeflush( self, data ):
pid = threading.current_thread().ident
self.queue.put( ( Console.MSG.WRITE, pid, data ) )
self.queue.put( ( Console.MSG.FLUSH, pid ) )
def flush( self, pid = None ):
self.queue.put( ( Console.MSG.FLUSH, pid if pid is not None else os.getpid() ) )
def flush( self ):
self.queue.put( ( Console.MSG.FLUSH, threading.current_thread().ident ) )
def clear( self, pid = None ):
self.queue.put( ( Console.MSG.CLEAR, pid if pid is not None else os.getpid() ) )
def clear( self ):
self.queue.put( ( Console.MSG.CLEAR, threading.current_thread().ident ) )
def __enter__( self ):
self.start( )
@ -325,16 +325,12 @@ class Console( threading.Thread ):
event = data[0]
if event == Console.MSG.SHUTDOWN:
# flush remaining buffers before shutting down
for ( pid, buffer ) in self.buffers.items( ):
for line in buffer:
print( line )
self.buffers.clear( )
self.buffer_write_times.clear( )
self.queue.task_done( )
#print(self.queue.qsize())
#print(self.queue.empty())
break
elif event == Console.MSG.WRITE:
@ -354,7 +350,8 @@ class Console( threading.Thread ):
elif event == Console.MSG.FLUSH:
pid = data[ 1 ]
if pid in self.buffers:
for line in self.buffers[ pid ]:
buffer = self.buffers[ pid ]
for line in buffer:
print( line )
self.buffers.pop( pid, None )
self.buffer_write_times[ pid ] = datetime.datetime.now( )