当前位置: 首页>>代码示例>>Python>>正文


Python Pool.apply_acync方法代码示例

本文整理汇总了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)
开发者ID:hostadmin,项目名称:tools,代码行数:72,代码来源:logsync.py


注:本文中的multiprocessing.Pool.apply_acync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。