Added basic worker thread back in, and TODO comments for multi-threading this new script.

This commit is contained in:
Brian 2014-05-13 20:45:55 -06:00
parent 59e010d682
commit 3ffdd76147
1 changed files with 38 additions and 0 deletions

View File

@ -212,6 +212,34 @@ class Console( threading.Thread ):
self.queue.task_done( ) self.queue.task_done( )
class Worker( threading.Thread ):
def __init__( self, console, queue, files_to_ignore ):
threading.Thread.__init__( self )
self.console = console
self.queue = queue
self.files_to_ignore = files_to_ignore
def run( self ):
while True:
( cmd, data ) = self.queue.get( )
if cmd == MSG.SHUTDOWN:
self.queue.task_done( )
self.console.flush( )
break
if cmd != MSG.PARSE_DIRECTORY or data is None:
self.console.flush( )
self.queue.task_done( )
continue
directory = data
# add threading stuffs
self.queue.task_done( )
def main( args ): def main( args ):
# check requirements # check requirements
if call_process( 'p4 -V' ) != 0: if call_process( 'p4 -V' ) != 0:
@ -242,8 +270,18 @@ def main( args ):
with Console( auto_flush_num=20, auto_flush_time=1000 ) as c: with Console( auto_flush_num=20, auto_flush_time=1000 ) as c:
if not options.quiet: if not options.quiet:
c.writeflush( "Caching files in depot, this may take a little while..." ) c.writeflush( "Caching files in depot, this may take a little while..." )
# TODO: push this off to a thread and walk the directory so we get a headstart.
files_in_depot = get_client_set( directory ) files_in_depot = get_client_set( directory )
# TODO: push a os.walk request off to a thread to build a list of files in the directory; create batch based on directory?
# TODO: at this point join on both tasks to wait until they're done
# TODO: kick off file removal, make batches from the files for threads to work on since testing has to be done for each.
# need to figure out the best way to do this since the ignore list needs to be properly built for each directory;
# will at least need to redo how the ignore lists are handled for efficiencies sake.
if not options.quiet: if not options.quiet:
c.writeflush( "Checking " + directory) c.writeflush( "Checking " + directory)
for root, dirs, files in os.walk( directory ): for root, dirs, files in os.walk( directory ):