• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python eventloop.add_idle函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中miro.eventloop.add_idle函数的典型用法代码示例。如果您正苦于以下问题:Python add_idle函数的具体用法?Python add_idle怎么用?Python add_idle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: device_changed

    def device_changed(self, id_, **kwargs):
        if id_ not in self.connected:
            # backend didn't send a connected message
            self.device_connected(id_, **kwargs)
            return

        info = self.connected[id_]

        if info.mount:
            # turn off the autosaving on the old database
            info.database.disconnect_all()
            eventloop.add_idle(write_database, 'writing database on change',
                               (info.database, info.mount))

        info = self._set_connected(id_, kwargs)

        if self._is_hidden(info):
            # don't bother with change message on devices we're not showing
            return

        if info.mount:
            self.info_cache.setdefault(info.mount, {})
            on_mount(info)
        else:
            sync_manager = app.device_manager.get_sync_for_device(info,
                                                                  create=False)
            if sync_manager:
                sync_manager.cancel()
        messages.TabsChanged('connect', [], [info], []).send_to_frontend()
        messages.DeviceChanged(info).send_to_frontend()
开发者ID:codito,项目名称:miro,代码行数:30,代码来源:devices.py


示例2: _copy_as_iter

 def _copy_as_iter(self):
     while self.copying:
         final_path, info = self.copying.popitem()
         iterable = fileutil.copy_with_progress(info.video_path, final_path,
                                                block_size=128 * 1024)
         try:
             for count in iterable:
                 self.progress_size[info.id] += count
                 if self.stopping:
                     iterable.close()
                     eventloop.add_idle(fileutil.delete,
                                        "deleting canceled sync",
                                        args=(final_path,))
                     final_path = None
                     break
                 # let other stuff run
                 self._schedule_sync_changed()
                 yield
         except IOError:
             final_path = None
         if final_path:
             self._add_item(final_path, info)
         # don't throw off the progress bar; we're done so pretend we got
         # all the bytes
         self.progress_size[info.id] = self.total_size[info.id]
         self.finished += 1
         self._check_finished()
         if self.stopping:
             break # no more copies
         yield
     self._copy_iter_running = False
开发者ID:codito,项目名称:miro,代码行数:31,代码来源:devices.py


示例3: update_finished

 def update_finished(self, feed):
     for callback_handle in self.callback_handles.pop(feed.id):
         feed.disconnect(callback_handle)
     self.currently_updating.remove(feed)
     # call run_update_queue in an idle to avoid re-updating the feed that
     # just finished.  That could cause weird effects since we are in the
     # update-finished callback right now.  See #16277
     eventloop.add_idle(self.run_update_queue, 'run feed update queue')
开发者ID:codito,项目名称:miro,代码行数:8,代码来源:feedupdate.py


示例4: check_description

 def check_description(self, data):
     if len(data) > MAX_TORRENT_SIZE or data[0] != 'd':
         # Bailout if we get too much data or it doesn't begin with
         # "d" (see #12301 for details)
         eventloop.add_idle(self.handle_corrupt_torrent,
                            'description check failed')
         return False
     else:
         return True
开发者ID:nxmirrors,项目名称:miro,代码行数:9,代码来源:download.py


示例5: run_next_update

    def run_next_update(self):
        if len(self.vital) > 0:
            item = self.vital.popleft()
        elif len(self.idle) > 0:
            item = self.idle.popleft()
        else:
            self.running_count -= 1
            return

        eventloop.add_idle(item.request_icon, "Icon Request")
开发者ID:CodeforEvolution,项目名称:miro,代码行数:10,代码来源:iconcache.py


示例6: call_handler

 def call_handler(self, method, message):
     # this executes in the thread reading from the subprocess pipe.  Move
     # things into the backend thread.
     self.handler_queue.put((method, message))
     if not self.safe_to_skip_add_idle:
         # we can skip calling add_idle() again if we put objects on the
         # queue before process_handler_queue() starts getting from it in
         # the event loop thread.
         self.safe_to_skip_add_idle = True
         eventloop.add_idle(self.process_handler_queue,
                            'process handler queue')
开发者ID:ShriramK,项目名称:miro,代码行数:11,代码来源:subprocessmanager.py


示例7: test_callbacks

 def test_callbacks(self):
     eventloop.add_idle(self.callback, "foo")
     eventloop.add_timeout(0.1, self.callback, "foo", args=("chris",),
                          kwargs={'hula': "hula"})
     eventloop.add_timeout(0.2, self.callback, "foo", args=("ben",),
                          kwargs={'hula': 'moreHula', 'stop': 1})
     self.runEventLoop()
     self.assertEquals(self.got_args[0], ())
     self.assertEquals(self.got_args[1], ("chris",))
     self.assertEquals(self.got_args[2], ("ben",))
     self.assertEquals(self.got_kwargs[0], {})
     self.assertEquals(self.got_kwargs[1], {'hula':'hula'})
     self.assertEquals(self.got_kwargs[2], {'hula': 'moreHula', 'stop': 1})
开发者ID:CodeforEvolution,项目名称:miro,代码行数:13,代码来源:schedulertest.py


示例8: update_finished

    def update_finished(self):
        if self.in_shutdown:
            self.running_count -= 1
            return

        if len(self.vital) > 0:
            item = self.vital.popleft()
        elif len(self.idle) > 0:
            item = self.idle.popleft()
        else:
            self.running_count -= 1
            return

        eventloop.add_idle(item.request_icon, "Icon Request")
开发者ID:ShriramK,项目名称:miro,代码行数:14,代码来源:iconcache.py


示例9: request_update

 def request_update(self, item, is_vital=False):
     if is_vital:
         item.dbItem.confirm_db_thread()
         if (item.filename and fileutil.access(item.filename, os.R_OK)
                and item.url == item.dbItem.get_thumbnail_url()):
             is_vital = False
     if self.started and self.running_count < RUNNING_MAX:
         eventloop.add_idle(item.request_icon, "Icon Request")
         self.running_count += 1
     else:
         if is_vital:
             self.vital.append(item)
         else:
             self.idle.append(item)
开发者ID:CodeforEvolution,项目名称:miro,代码行数:14,代码来源:iconcache.py


示例10: handle_message

 def handle_message(self, data):
     # import this stuff inside the function, so that import errors don't
     # mess with other code, which is part of the startup process
     from miro import app
     from miro import eventloop
     from miro.commandline import parse_command_line_args
     import gobject
     try:
         cmd_line = pickle.loads(data)
     except:
         logging.warn("Error unpickling message (%r)" % data)
     else:
         args = commandline.parse_command_line_string(cmd_line)
         eventloop.add_idle(parse_command_line_args, 
                 'parse command line', args=(args[1:],))
         if (hasattr(app, "widgetapp") and app.widgetapp is not None and
                 app.widgetapp.window is not None):
             gobject.idle_add(app.widgetapp.window._window.present)
开发者ID:nxmirrors,项目名称:miro,代码行数:18,代码来源:pipeipc.py


示例11: exec_codegen

def exec_codegen(codegen_info, media_path, callback, errback):
    """Run an echonest codegen in a worker thread.

    This method should work for both ENMFP and echoprint.

    On success, callback(media_path, echonest_code) will be called.

    On error, errback(media_path, exception) will be called.
    """
    if cant_run_codegen():
        # use add_idle to send the errback to make the timing closer to normal
        # operations.  Some code could potentially break if the errback runs
        # before this function returns.
        eventloop.add_idle(errback, 'exec_codegen errback',
                           args=(CodegenNotSupported(),))
        return

    codegen_path = codegen_info['path']
    codegen_env = codegen_info.get('env')
    def thread_function():
        stdout = util.call_command(codegen_path, media_path, env=codegen_env)
        results = json.loads(stdout)
        # not sure why the code generator always returns a 1-element list, but
        # it does
        results = results[0]
        if 'error' in results:
            raise CodegenError(results['error'])
        # NOTE: both codegens return some metadata that we can use, but
        # mutagen can get the same data so let's just pay attention to the
        # code.
        return results['code']

    def thread_callback(code):
        callback(media_path, code)

    def thread_errback(error):
        errback(media_path, error)

    logging.debug("Invoking echonest codegen on %s", media_path)
    eventloop.call_in_thread(thread_callback, thread_errback, thread_function,
                             'exec echonest codegen')
开发者ID:CodeforEvolution,项目名称:miro,代码行数:41,代码来源:echonest.py


示例12: launch

def launch():
    # Make all output flush immediately.
    # Don't add extra import statements here.  If there's a problem importing
    # something we want to see the error in the log.
    import logging
    import sys
    import os
    from miro import util

    sys.stdout = util.AutoFlushingStream(sys.stdout)
    sys.stderr = sys.stdout

    override_modules()

    from miro.plat.utils import setup_logging, initialize_locale
    setup_logging(in_downloader=True)
    util.setup_logging()
    initialize_locale()

    if os.environ.get('DEMOCRACY_DOWNLOADER_FIRST_LAUNCH') != '1':
        logging.info("Starting new downloader log")
    else:
        logging.info("Launching Downloader Daemon")
    log_versions()

    # Start of normal imports
    import threading

    from miro.dl_daemon import daemon
    from miro import httpclient

    addr = os.environ['DEMOCRACY_DOWNLOADER_ADDR']
    port = int(os.environ['DEMOCRACY_DOWNLOADER_PORT'])
    short_app_name = os.environ['DEMOCRACY_SHORT_APP_NAME']
    httpclient.start_thread()
    server = daemon.DownloaderDaemon(addr, port, short_app_name)
    # setup config for the downloader
    from miro import eventloop
    config.load(config.DownloaderConfig())
    app.downloader_config_watcher = config.ConfigWatcher(
            lambda foo, *args: eventloop.add_idle(foo, "config watcher",
                args=args))
    # start things up
    eventloop.startup()
开发者ID:nxmirrors,项目名称:miro,代码行数:44,代码来源:Democracy_Downloader.py


示例13: _grab_file_url

def _grab_file_url(url, callback, errback, default_mime_type):
    path = download_utils.get_file_url_path(url)
    try:
        f = file(path)
    except EnvironmentError:
        eventloop.add_idle(errback, 'grab file url errback',
                args=(FileURLNotFoundError(path),))
    else:
        try:
            data = f.read()
        except IOError:
            eventloop.add_idle(errback, 'grab file url errback',
                    args=(FileURLReadError(path),))
        else:
            info = {"body": data,
                          "updated-url":url,
                          "redirected-url":url,
                          "content-type": default_mime_type,
                          }
            eventloop.add_idle(callback, 'grab file url callback',
                    args=(info,))
开发者ID:adarshr,项目名称:miro,代码行数:21,代码来源:httpclient.py


示例14: call_callback

 def call_callback(self, info):
     self._cleanup_filehandle()
     msg = 'curl transfer callback: %s' % (self.callback,)
     eventloop.add_idle(self.callback, msg, args=(info,))
开发者ID:CodeforEvolution,项目名称:miro,代码行数:4,代码来源:httpclient.py


示例15: call_handler

 def call_handler(self, method, message):
     # this executes in the thread reading from the subprocess pipe.  Move
     # things into the backend thread.
     name = 'handle subprocess message: %s' % message
     eventloop.add_idle(method, name, args=(message,))
开发者ID:paulmaki,项目名称:miro,代码行数:5,代码来源:subprocessmanager.py


示例16: _on_menu_update

 def _on_menu_update(self, manager, reason):
     eventloop.add_idle(self.calculate_popup_menu, "Update app indicator menu")
开发者ID:nerdymcgee,项目名称:miro,代码行数:2,代码来源:miroappindicator.py


示例17: call_errback

 def call_errback(self, error):
     self._cleanup_filehandle()
     msg = 'curl transfer errback: %s' % (self.errback,)
     eventloop.add_idle(self.errback, msg, args=(error,))
开发者ID:CodeforEvolution,项目名称:miro,代码行数:4,代码来源:httpclient.py


示例18: send

 def send(self, callback=None):
     if self.daemon.shutdown:
         return
     eventloop.add_idle(lambda : self.daemon.send(self, callback),
                        "sending command %r" % self)
开发者ID:levjj,项目名称:miro,代码行数:5,代码来源:command.py


示例19: call_errback

 def call_errback(self, error):
     self._cleanup_filehandle()
     eventloop.add_idle(self.errback, 'curl transfer errback',
                        args=(error,))
开发者ID:adarshr,项目名称:miro,代码行数:4,代码来源:httpclient.py


示例20: call_callback

 def call_callback(self, info):
     self._cleanup_filehandle()
     eventloop.add_idle(self.callback, 'curl transfer callback',
             args=(info,))
开发者ID:adarshr,项目名称:miro,代码行数:4,代码来源:httpclient.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python eventloop.add_timeout函数代码示例发布时间:2022-05-27
下一篇:
Python clock.clock函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap