本文整理汇总了Python中multiprocessing.Pool.apply_acync方法的典型用法代码示例。如果您正苦于以下问题:Python Pool.apply_acync方法的具体用法?Python Pool.apply_acync怎么用?Python Pool.apply_acync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Pool
的用法示例。
在下文中一共展示了Pool.apply_acync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LogSync
# 需要导入模块: from multiprocessing import Pool [as 别名]
# 或者: from multiprocessing.Pool import apply_acync [as 别名]
class LogSync(object):
def __init__(self, withSuffix=None, logDir=None, maxProc=multiprocessing.cpu_count(), configFile='./logsync.json'):
"""
Inital method for base class LogSync
:param withSuffix: if is False - not use suffix in self.logDir
:param logDir: define self.logPath (without suffix, it will be added)
:param maxProc: max proccesses in pool of child proc for async calls
:param configFile: config file location (logsync.json)
"""
try:
with open(configFile, 'rb') as f:
self.cfg = json.load(f)
except IOError:
raise ConfigNotFound(configFile)
except ValueError:
raise ErrorConfigParse(configFile)
except Exception as e:
raise e
if logDir:
self.logPath = logDir
elif withSuffix:
self.logPath = os.path.join(logDir, withSuffix)
else:
raise noSyncError
self.procpool = Pool(processes = maxProc)
self.fList=[]
def handler(self, body):
self.listLogs(body)
self.syncWrapper()
def syncWrapper(self):
for logFile in self.fList:
self.procpool.apply_acync(self.syncWrapper, args = logFile)
def listLogs(self, body):
fileMask = self.cfg['logger']['fmask']['prefix'] + str(body) + self.cfg['logger']['fmask']['suffix']
for root, dirs, files in os.walk(self.logPath):
for filename in fnmatch.filter(files, fileMask):
self.listReplays(os.path.join(root, filename))
self.fList.append = os.path.join(root, filename)
def listReplays(self, logFile):
if self.cfg['logger']['parseReplays']:
try:
with open(logFile, 'r+') as f:
fdata = mmap.mmap(f.fileno(), 0)
m = re.search(self.cfg['logger']['replayPattern'], fdata)
if m:
fmaskBody = m.groups()[0]
fmask = self.cfg['logger']['rmask']['prefix'] + fmaskBody + self.cfg['logger']['rmask'][
'suffix']
for root, dirs, files in os.walk(self.logPath):
for filename in fnmatch.filter(fmask):
self.fList.append = os.path.join(root, filename)
except IOError:
raise ConfigNotFound(logFile)
except AttributeError:
raise ErrorConfigParse
def sync(self, logFile):
"""
Abstract method just remove log file from query
:param logFile: file to operate
"""
self.fList.remove(logFile)