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


Python ThreadPool.starmap_async方法代码示例

本文整理汇总了Python中multiprocessing.pool.ThreadPool.starmap_async方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.starmap_async方法的具体用法?Python ThreadPool.starmap_async怎么用?Python ThreadPool.starmap_async使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.pool.ThreadPool的用法示例。


在下文中一共展示了ThreadPool.starmap_async方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: seg

# 需要导入模块: from multiprocessing.pool import ThreadPool [as 别名]
# 或者: from multiprocessing.pool.ThreadPool import starmap_async [as 别名]
def seg(request):
    """View for seg."""
    if request.method == 'POST':
        data = json.loads(request.body.decode('utf-8'))
        source_text = data['source_text']
        source_text = source_text.replace('\n', ' ')  # remove linebreaks
        segmentators = data['segmentators']
        segmentators = [i.lower() for i in segmentators]
        pool = ThreadPool(processes=5)
        res = pool.starmap_async(_segwrap, zip(segmentators, repeat(source_text)))
        vals = res.get()
        seg_with_diff = segcomp(vals)
        return HttpResponse(json.dumps(seg_with_diff), content_type="application/json")
    elif request.method == 'GET':
        return HttpResponse('')

    return Http404
开发者ID:amigcamel,项目名称:diffseg,代码行数:19,代码来源:views.py

示例2: PiperBot

# 需要导入模块: from multiprocessing.pool import ThreadPool [as 别名]
# 或者: from multiprocessing.pool.ThreadPool import starmap_async [as 别名]

#.........这里部分代码省略.........
            func()
        del self.plugins[plugin_name]

    def handle_message(self, message):
        if message.command == "PING":
            response = message.copy()
            response.command = "PONG"
            self.send(response)
        elif message.command == "PRIVMSG":
            self.message_buffer[message.server][message.params].appendleft(message)

            if message.text.startswith(self.command_char) and message.text[1:]:
                first = message.text[1:].split()[0]
                if first == "alias":
                    self.handle_alias_assign(message)
                elif first in self.commands or first in self.aliases:
                    self.worker_pool.apply_async(self.handle_command,  args=(message,))

        triggered = []
        for plugin in self.plugins.values():
            if message.command == "PRIVMSG":
                for regex, rfunc in plugin._regexes:
                    matches = regex.findall(message.text)
                    for groups in matches:
                        temp = message.copy()
                        temp.groups = groups
                        triggered.append((rfunc, temp, self.pre_regex_exts, self.post_trigger_exts))
            for trigger, tfunc in plugin._triggers:
                if trigger(message, bot):
                    triggered.append((tfunc, message, self.pre_trigger_exts, self.post_trigger_exts))
            for event, efunc in plugin._handlers:
                if message.command.lower() == event.lower():
                    triggered.append((efunc, message, self.pre_event_exts, self.post_event_exts))
        self.worker_pool.starmap_async(self.call_triggered, triggered, error_callback=print)

    def call_triggered(self, func, message, pre=[], post=[]):
        pipe = self.resulter()

        for _, _, func_, in post:
                pipe = func_(message, pipe)

        pipe = func(pipe)
        next(pipe)
        for _, _, func_ in pre:
            pipe = func_(message, pipe)

        pipe.send(message)

    def handle_alias_assign(self, message):
        try:
            name, *alias = message.text[len(self.command_char)+5:].split("=")
            name = name.strip()
            alias = "=".join(alias).strip()
            if name in self.commands:
                raise Exception("cannot overwrite existing command")

            commands = map(lambda x: [(command, " ".join(args)) for command, *args in [x.split(" ")]][0],
                           map(lambda x: x.strip(), alias.split(" || ")))
            funcs = []
            args = []
            for func, arg in commands:
                if func in self.commands:
                        funcs.append(self.commands[func][1]["command"])
                        args.append(arg)
                elif func in self.aliases:
                    if func == name:
开发者ID:egelmex,项目名称:piperbot,代码行数:70,代码来源:piperbot.py


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