本文整理汇总了Python中multiprocessing.dummy.Pool.messages方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.messages方法的具体用法?Python Pool.messages怎么用?Python Pool.messages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.dummy.Pool
的用法示例。
在下文中一共展示了Pool.messages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main2
# 需要导入模块: from multiprocessing.dummy import Pool [as 别名]
# 或者: from multiprocessing.dummy.Pool import messages [as 别名]
def main2():
from multiprocessing.dummy import Pool as ThreadPool
from threading import Lock
import Queue
import Directory
import DirectoryDB
def create_FindIt_folder():
import sys
if sys.platform == "win32":
appdata = os.getenv('APPDATA')
FindIt = os.path.join(appdata, "FindIt")
if not os.path.isdir(FindIt):
os.mkdir(FindIt)
if os.path.isdir(FindIt):
return FindIt
else:
return False
elif sys.platform == "linux2":
home = os.getenv('HOME')
FindIt = os.path.join(home, "FindIt")
if not os.path.isdir(FindIt):
os.mkdir(FindIt)
if os.path.isdir(FindIt):
return FindIt
else:
return False
else:
print "Crashing. Not made to run on mac"
def init_database():
FindIt = create_FindIt_folder()
if not FindIt:
print "Could not create the FindIt directory. Will now crash."
quit()
database_filename = os.path.join(FindIt, "test.db")
# self.backup_db(database_filename)
directory_database = DirectoryDB.DirectoryDB(database_filename)
directory_database.start()
return directory_database
def linux_path(path):
if ":" in path:
drive = path[0]
path = "/media/" + drive.upper() + path[2:]
path = path.replace("\\", "/")
return path
import sys
for times in range(10):
directory_database = init_database()
directory_dictionary = {}
number_of_threads = 16
update_pool = ThreadPool(number_of_threads)
update_pool.thread_count = 0
update_pool.thread_lock = Lock()
update_pool.messages = Queue.Queue()
path = "O:\\Technical_Support\\Applications_Engineering"
if sys.platform == "linux2":
path = linux_path(path)
log("Scanning:", path)
t = time.time()
if path not in directory_dictionary:
directory_dictionary[path] = Directory.Directory(path, 0.0,
directory_dictionary) # Create Root and reset time.
update_pool.apply_async(directory_dictionary[path].update,
args=(update_pool, directory_database,)) # Go. Scan. Be Free.
time.sleep(.1)
while update_pool.thread_count > 0:
time.sleep(.001)
update_pool.close()
update_pool.join()
log("Time to scan directory:", time.time() - t)
paths = directory_database.dump_paths()
if sys.platform == "linux2":
lpaths = []
for path, t in paths:
lpaths.append((linux_path(path), t))
paths = lpaths
t = time.time()
for path, scan_time in paths:
if os.path.getmtime(path) > scan_time:
print path
tt = time.time() - t
log("Time to scan all", len(paths), "folders:", tt, "(", len(paths) / tt, "Folder/ second)")
def get_date(path, scan_time):
return os.path.getmtime(path) > scan_time
from multiprocessing.pool import ThreadPool as Pool
pool = Pool(100)
t = time.time()
pool.map(lambda (path, scan_time): os.path.getmtime(path) > scan_time, paths) # This is very fast.
#.........这里部分代码省略.........