77See the file 'doc/COPYING' for copying permission
88"""
99
10+ import threading
1011import time
1112
1213from lib .core .common import clearConsoleLine
@@ -29,27 +30,59 @@ def tableExists(tableFile):
2930 infoMsg = "checking table existence using items from '%s'" % tableFile
3031 logger .info (infoMsg )
3132
32- count = 0
33+ count = [ 0 ]
3334 length = len (tables )
35+ threads = []
36+ tbllock = threading .Lock ()
37+ iolock = threading .Lock ()
38+ kb .locks .seqLock = threading .Lock ()
39+ kb .threadContinue = True
40+
41+ def tableExistsThread ():
42+ while count [0 ] < length and kb .threadContinue :
43+ tbllock .acquire ()
44+ table = tables [count [0 ]]
45+ count [0 ] += 1
46+ tbllock .release ()
47+
48+ if conf .db and not conf .db .endswith (METADB_SUFFIX ):
49+ table = "%s.%s" % (conf .db , table )
50+ result = inject .checkBooleanExpression ("%s" % safeStringFormat ("EXISTS(SELECT %d FROM %s)" , (randomInt (1 ), table )))
51+
52+ iolock .acquire ()
53+ if result :
54+ retVal .append (table )
3455
35- for table in tables :
36- if conf .db and not conf .db .endswith (METADB_SUFFIX ):
37- table = "%s.%s" % (conf .db , table )
38- result = inject .checkBooleanExpression ("%s" % safeStringFormat ("EXISTS(SELECT %d FROM %s)" , (randomInt (1 ), table )))
39-
40- if result :
41- retVal .append (table )
56+ if conf .verbose in (1 , 2 ):
57+ clearConsoleLine (True )
58+ infoMsg = "\r [%s] [INFO] retrieved: %s\n " % (time .strftime ("%X" ), table )
59+ dataToStdout (infoMsg , True )
4260
4361 if conf .verbose in (1 , 2 ):
44- clearConsoleLine (True )
45- infoMsg = "\r [%s] [INFO] retrieved: %s\n " % (time .strftime ("%X" ), table )
46- dataToStdout (infoMsg , True )
47-
48- count += 1
49-
50- if conf .verbose in (1 , 2 ):
51- status = '%d/%d items (%d%s)' % (count , length , round (100.0 * count / length ), '%' )
52- dataToStdout ("\r [%s] [INFO] tried: %s" % (time .strftime ("%X" ), status ), True )
62+ status = '%d/%d items (%d%s)' % (count [0 ], length , round (100.0 * count [0 ]/ length ), '%' )
63+ dataToStdout ("\r [%s] [INFO] tried: %s" % (time .strftime ("%X" ), status ), True )
64+ iolock .release ()
65+
66+ # Start the threads
67+ for numThread in range (conf .threads ):
68+ thread = threading .Thread (target = tableExistsThread , name = str (numThread ))
69+ thread .start ()
70+ threads .append (thread )
71+
72+ # And wait for them to all finish
73+ try :
74+ alive = True
75+ while alive :
76+ alive = False
77+ for thread in threads :
78+ if thread .isAlive ():
79+ alive = True
80+ thread .join (5 )
81+ except KeyboardInterrupt :
82+ kb .threadContinue = False
83+ raise
84+ finally :
85+ kb .locks .seqLock = None
5386
5487 clearConsoleLine (True )
5588
0 commit comments