r14206 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14205‎ | r14206 | r14207 >
Date:22:10, 13 May 2006
Author:brion
Status:old
Tags:
Comment:
Make debug verbosity and number of threads command-line args
Modified paths:
  • /trunk/tools/dbzip2/dbzip2 (modified) (history)

Diff [purge]

Index: trunk/tools/dbzip2/dbzip2
@@ -20,7 +20,6 @@
2121 # TODO:
2222 # Remote compressors
2323 # Use a thread pool?
24 -# Selectable number of threads
2524 # Selectable remote threads
2625 # Selectable block size
2726 # Handle remote failures gracefully
@@ -28,30 +27,38 @@
2928 # Accept file input/output, behavior like bzip2
3029
3130 import bz2
 31+import getopt
3232 import sys
3333 import thread
3434 import time
3535
3636 class Compressor(object):
37 - def __init__(self, inputStream, outputStream):
38 - self.inputStream = inputStream
39 - self.outputStream = outputStream
 37+ def __init__(self, args):
 38+ self.inputStream = sys.stdin
 39+ self.outputStream = sys.stdout
4040 self.blockSize = 900000 # 900k default blocksize
4141 self.queue = []
4242 self.done = False
43 - self.maxQueued = 2
 43+ self.threads = 1
4444 self.readCount = 0
4545 self.writeCount = 0
4646 self.verbosity = 0
4747 self.threadLock = thread.allocate_lock()
 48+ self.processArgs(args)
4849
 50+ def processArgs(self, args):
 51+ (options, remainder) = getopt.getopt(args, "vp:")
 52+ for (opt, val) in options:
 53+ if opt == "-v":
 54+ self.verbosity += 1
 55+ elif opt == "-p":
 56+ self.threads = int(val)
 57+
4958 def debug(self, level, text):
5059 if self.verbosity >= level:
5160 sys.stderr.write(text + "\n")
5261
5362 def run(self):
54 - #thread.start_new_thread(self.writerThread, ())
55 - #self.readerThread()
5663 thread.start_new_thread(self.readerThread, ())
5764 self.writerThread()
5865
@@ -93,7 +100,7 @@
94101
95102 def ready(self):
96103 """Check if we've gone over the limit of waiting connections."""
97 - return len(self.queue) < self.maxQueued
 104+ return len(self.queue) < self.threads
98105
99106 def dispatch(self, block):
100107 """Queue a block of data for remote compression."""
@@ -184,5 +191,5 @@
185192 return bz2.compress(self.input)
186193
187194 if __name__ == "__main__":
188 - compressor = Compressor(sys.stdin, sys.stdout)
 195+ compressor = Compressor(sys.argv[1:])
189196 compressor.run()

Status & tagging log