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

Python eventloop.add_timeout函数代码示例

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

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



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

示例1: _log_bug_report_progress

 def _log_bug_report_progress(self, sender):
     current, total = sender.progress()
     if current < total:
         logging.info("Crash report progress: %0.1f",
                 current * 100.0 / total)
         eventloop.add_timeout(1.0, self._log_bug_report_progress,
                 'log bug report progress', args=(sender,))
开发者ID:nxmirrors,项目名称:miro,代码行数:7,代码来源:controller.py


示例2: _handle_app_cast

def _handle_app_cast(data, up_to_date_callback):
    """Handle appcast data when it's correctly fetched
    """
    try:
        appcast = feedparserutil.parse(data['body'])
        if appcast['bozo'] == '1':
            return

        up_to_date = True
        latest = _get_item_for_latest(appcast)
        if latest is None:
            logging.info('No updates for this platform.')
            # this will go through the finally clause below
            return

        serial = int(app.config.get(prefs.APP_SERIAL))
        up_to_date = (serial >= _get_item_serial(latest))

        if not up_to_date:
            logging.info('New update available.')
            signals.system.update_available(latest)
        elif up_to_date_callback:
            logging.info('Up to date.  Notifying callback.')
            up_to_date_callback()
        else:
            logging.info('Up to date.')

    except StandardError:
        logging.exception("Error while handling appcast data.")
    finally:
        global check_in_progress
        check_in_progress = False
        eventloop.add_timeout(86400, check_for_updates, "Check for updates")
开发者ID:codito,项目名称:miro,代码行数:33,代码来源:autoupdate.py


示例3: check_content

 def check_content(data):
     self.check_content_data = data
     if len(data) == 5:
         # wait a bit to see if any more data comes through, which it
         # shouldn't
         eventloop.add_timeout(0.2, self.stopEventLoop, 'stop download',
                 args=(False,))
         1/0
     return True
开发者ID:bluezone,项目名称:miro,代码行数:9,代码来源:httpclienttest.py


示例4: send_bug_report

 def send_bug_report(self, report, description, send_database, quit_after=False):
     sender = BugReportSender(report, description, send_database)
     self.bug_report_senders.add(sender)
     sender.connect("finished", self._bug_report_sent)
     if quit_after:
         self._quit_after_bug_reports = True
         eventloop.add_timeout(0.5, self._start_send_bug_report_progress, "bug report progress")
     else:
         eventloop.add_timeout(0.5, self._log_bug_report_progress, "log bug report progress", args=(sender,))
开发者ID:cool-RR,项目名称:Miro,代码行数:9,代码来源:controller.py


示例5: clean_up

def clean_up(temp_file, file_and_directory=False, attempts=0):
    if attempts > 5:
        return
    if os.path.exists(temp_file):
        try:
            os.remove(temp_file)
        except EnvironmentError, e:
            logging.debug("clean_up: %s kicked up while removing %s", e, temp_file)
            timeout = 1.0 * attempts
            eventloop.add_timeout(
                timeout, clean_up, "conversion clean_up attempt", (temp_file, file_and_directory, attempts + 1)
            )
开发者ID:cool-RR,项目名称:Miro,代码行数:12,代码来源:conversions.py


示例6: do_update

 def do_update(self):
     try:
         TORRENT_SESSION.update_torrents()
         statuses = []
         for downloader in self.to_update:
             statuses.append(downloader.get_status())
         self.to_update = set()
         if statuses:
             command.BatchUpdateDownloadStatus(daemon.LAST_DAEMON,
                     statuses).send()
     finally:
         eventloop.add_timeout(self.UPDATE_CLIENT_INTERVAL, self.do_update,
                 "Download status update")
开发者ID:nxmirrors,项目名称:miro,代码行数:13,代码来源:download.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: _on_thread_quit

    def _on_thread_quit(self, thread):
        """Handle our thread exiting."""

        # Ignore this call if it was queued from while we were in the middle
        # of shutdown().
        if not self.is_running:
            return

        if thread is not self.thread:
            # If we have lost the race between the cleanup on shutdown
            # it should be safe to ignore.
            #
            # This can happen when the process does not immediately shut down
            # because the worker process is still processing pending jobs
            # and the quit message was not processed in time and so the
            # subprocess was forcibly terminated.  When that happens
            # _cleanup_process() is called which resets the thread attribute
            # to None immediately, but _on_thread_quit() is only run some
            # time after that (when we notice the pipe to the subprocess's
            # close we add _on_thread_quit() to the idle loop).
            #
            # So if the self.thread attribute is None then it means we are done
            # and so things are all good.
            if self.thread is not None and thread.quit_type != thread.QUIT_NORMAL:
                msg = ('_on_thread_quit called by an old thread '
                        'self.thread: %s thread: %s quit_type: %s' %
                        (self.thread.name, thread.name, thread.quit_type))
                app.controller.failed_soft('handling subprocess', msg)
            return

        if (self.thread.quit_type == self.thread.QUIT_NORMAL and
            self.sent_quit):
            self._cleanup_process()
        else:
            logging.warn("Subprocess quit unexpectedly (quit_type: %s, "
                         "sent_quit: %s).  Will restart subprocess",
                         self.thread.quit_type, self.sent_quit)
            # NOTE: should we enforce some sort of cool-down time before
            # restarting the subprocess?
            time_since_start = clock.clock() - self.start_time
            delay_time = self.restart_delay - time_since_start
            if delay_time <= 0:
                logging.warn("Subprocess died after %0.1f seconds.  "
                             "Restarting", time_since_start)
                self.restart()
            else:
                logging.warn("Subprocess died in %0.1f seconds, waiting "
                             "%0.1f to restart", time_since_start, delay_time)
                eventloop.add_timeout(delay_time, self.restart,
                                      'restart failed subprocess')
开发者ID:ShriramK,项目名称:miro,代码行数:50,代码来源:subprocessmanager.py


示例9: test_lots_of_threads

 def test_lots_of_threads(self):
     timeouts = [0, 0, 0.1, 0.2, 0.3]
     threadCount = 8
     def thread():
         sleep(0.5)
         for timeout in timeouts:
             eventloop.add_timeout(timeout, self.callback, "foo")
     for i in range(threadCount):
         t = threading.Thread(target=thread)
         t.start()
     eventloop.add_timeout(1.2, self.callback, "foo", kwargs={'stop':1})
     self.runEventLoop()
     totalCalls = len(timeouts) * threadCount + 1
     self.assertEquals(len(self.got_args), totalCalls)
开发者ID:CodeforEvolution,项目名称:miro,代码行数:14,代码来源:schedulertest.py


示例10: update_stats

 def update_stats(self):
     """Update the download rate and eta based on receiving length
     bytes.
     """
     if self.client is None or self.state != 'downloading':
         return
     stats = self.client.get_stats()
     if stats.status_code in (200, 206):
         self.currentSize = stats.downloaded + stats.initial_size
         self.rate = stats.download_rate
     else:
         self.currentSize = self.rate = 0
     eventloop.add_timeout(self.CHECK_STATS_TIMEOUT, self.update_stats,
             'update http downloader stats')
     DOWNLOAD_UPDATER.queue_update(self)
开发者ID:nxmirrors,项目名称:miro,代码行数:15,代码来源:download.py


示例11: start_download

    def start_download(self, resume=True):
        if self.retryDC:
            self.retryDC.cancel()
            self.retryDC = None
        if resume:
            resume = self._resume_sanity_check()

        logging.info("start_download: %s", self.url)

        self.client = httpclient.grab_url(
            self.url, self.on_download_finished, self.on_download_error,
            header_callback=self.on_headers, write_file=self.filename,
            resume=resume)
        self.update_client()
        eventloop.add_timeout(self.CHECK_STATS_TIMEOUT, self.update_stats,
                'update http downloader stats')
开发者ID:nxmirrors,项目名称:miro,代码行数:16,代码来源:download.py


示例12: __call__

 def __call__(self, database):
     self.database = database
     if self.scheduled_write:
         return
     self.scheduled_write = eventloop.add_timeout(self.SAVE_INTERVAL,
                                                  self.write,
                                                  'writing device database')
开发者ID:codito,项目名称:miro,代码行数:7,代码来源:devices.py


示例13: test_remove_file

 def test_remove_file(self):
     filename = self.make_temp_path(".txt")
     self.httpserver.pause_after(5)
     def cancel_after_5_bytes():
         if self.client.get_stats().downloaded == 5:
             self.client.cancel(remove_file=True)
             self.stopEventLoop(False)
         else:
             eventloop.add_timeout(0.1, cancel_after_5_bytes, 'cancel')
     eventloop.add_timeout(0.1, cancel_after_5_bytes, 'cancel')
     self.expecting_errback = True
     self.grab_url(self.httpserver.build_url('test.txt'),
             write_file=filename)
     self.assertEquals(self.grab_url_info, None)
     self.assertEquals(self.grab_url_error, None)
     self.wait_for_libcurl_manager()
     self.assert_(not os.path.exists(filename))
开发者ID:bluezone,项目名称:miro,代码行数:17,代码来源:httpclienttest.py


示例14: startReadTimeout

 def startReadTimeout(self):
     if self.disable_read_timeout:
         return
     self.lastClock = clock()
     if self.readTimeout is not None:
         return
     self.readTimeout = eventloop.add_timeout(SOCKET_INITIAL_READ_TIMEOUT, self.onReadTimeout,
             "AsyncSocket.onReadTimeout")
开发者ID:cool-RR,项目名称:Miro,代码行数:8,代码来源:net.py


示例15: test_upload_progress

    def test_upload_progress(self):
        # upload a 100k file
        data = '0' * (1000 * 1024)
        f1 = {
            'filename': 'testing.txt',
            'mimetype': 'text/plain',
            'handle': StringIO(data),
        }
        self.event_loop_timeout = 5
        TIMEOUT = 0.001

        self.last_uploaded = None
        self.last_total = None
        self.saw_total = False

        def check_upload_progress():
            progress = self.client.get_stats()
            if progress.upload_total == -1:
                # client didn't know the total upload at this point.
                self.assertEquals(progress.uploaded, -1)
                eventloop.add_timeout(TIMEOUT, check_upload_progress,
                                      'upload progress timeout')
                return
            self.saw_total = True

            if self.last_uploaded is not None:
                # the currently upload size should only increase
                self.assert_(progress.uploaded >= self.last_uploaded)
            self.last_uploaded = progress.uploaded

            if self.last_total is not None:
                # the total upload size shouldn't change
                self.assertEquals(progress.upload_total, self.last_total)
            self.last_total = progress.upload_total

            eventloop.add_timeout(TIMEOUT, check_upload_progress,
                                  'upload progress timeout')

        eventloop.add_timeout(TIMEOUT, check_upload_progress,
                              'upload progress timeout')
        self.grab_url(
            self.httpserver.build_url('test.txt'), post_files={'file1': f1})

        # make sure at least one of our sending_progress() calls worked
        self.assert_(self.saw_total)
开发者ID:ktan2020,项目名称:miro,代码行数:45,代码来源:httpclienttest.py


示例16: test_cancel

 def test_cancel(self):
     filename = self.make_temp_path(".txt")
     self.httpserver.pause_after(5)
     def cancel_after_5_bytes():
         if self.client.get_stats().downloaded == 5:
             self.client.cancel()
             self.stopEventLoop(False)
         else:
             eventloop.add_timeout(0.1, cancel_after_5_bytes, 'cancel')
     eventloop.add_timeout(0.1, cancel_after_5_bytes, 'cancel')
     self.expecting_errback = True
     self.grab_url(self.httpserver.build_url('test.txt'),
             write_file=filename)
     # Neither the callback, nor the errback should be called
     self.assertEquals(self.grab_url_info, None)
     self.assertEquals(self.grab_url_error, None)
     # We shouldn't delete the file
     self.assert_(os.path.exists(filename))
开发者ID:bluezone,项目名称:miro,代码行数:18,代码来源:httpclienttest.py


示例17: get_startup_activity

 def get_startup_activity(self):
     self.confirm_db_thread()
     activity = self.status.get("activity")
     if activity is None and self.status.get("retryCount", -1) > -1 and "retryTime" in self.status:
         activity = self._calc_retry_time()
         if self._update_retry_time_dc is None:
             self._update_retry_time_dc = eventloop.add_timeout(1, self._update_retry_time, "Updating retry time")
     if activity is None:
         return _("starting up")
     return activity
开发者ID:nerdymcgee,项目名称:miro,代码行数:10,代码来源:downloader.py


示例18: test_quick_cancel

 def test_quick_cancel(self):
     # Try canceling before find_http_auth returns and make sure things
     # work.
     self.setup_answer("user", "password")
     url = self.httpserver.build_url('protected/index.txt')
     self.grab_url_error = self.grab_url_info = None
     self.client = httpclient.grab_url(url, self.grab_url_callback,
             self.grab_url_errback)
     # at this point, our client should be finding the HTTP auth.  It
     # shouldn't have started transfering data.
     self.assertEquals(len(httpclient.curl_manager.transfer_map), 0)
     self.client.cancel()
     self.expecting_errback = True
     eventloop.add_timeout(0.2, self.stopEventLoop, 'stopping event loop',
             args=(False,))
     self.runEventLoop(timeout=self.event_loop_timeout)
     # make sure that the callback/errback weren't called and nothing is
     # transfering
     self.check_nothing_called()
     self.assertEquals(len(httpclient.curl_manager.transfer_map), 0)
开发者ID:bluezone,项目名称:miro,代码行数:20,代码来源:httpclienttest.py


示例19: _send_bug_report_progress

 def _send_bug_report_progress(self):
     current_sent = 0
     total_to_send = 0
     for sender in self.bug_report_senders:
         sent, to_send = sender.progress()
         if to_send == 0:
             # this sender doesn't know it's total data, we can't calculate
             # things.
             current_sent = total_to_send = 0
             break
         else:
             current_sent += sent
             total_to_send += to_send
     if total_to_send > 0:
         progress = float(current_sent) / total_to_send
     else:
         progress = -1
     text = _("Sending Crash Report (%(progress)d%%)", {"progress": progress * 100})
     messages.ProgressDialog(text, progress).send_to_frontend()
     eventloop.add_timeout(0.1, self._send_bug_report_progress, "bug report progress")
开发者ID:cool-RR,项目名称:Miro,代码行数:20,代码来源:controller.py


示例20: error_callback

    def error_callback(self, url, error=None):
        self.dbItem.confirm_db_thread()

        if self.removed:
            iconCacheUpdater.update_finished()
            return

        # Don't clear the cache on an error.
        if self.url != url:
            self.url = url
            self.etag = None
            self.modified = None
            self.icon_changed()
        self.updating = False
        if self.needsUpdate:
            self.needsUpdate = False
            self.request_update(True)
        elif error is not None:
            eventloop.add_timeout(3600, self.request_update, "Thumbnail request for %s" % url)
        iconCacheUpdater.update_finished()
开发者ID:nxmirrors,项目名称:miro,代码行数:20,代码来源:iconcache.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python eventloop.add_urgent_call函数代码示例发布时间:2022-05-27
下一篇:
Python eventloop.add_idle函数代码示例发布时间: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