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


Python eventloop.add_timeout函数代码示例

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


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


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