Beispiel #1
0
def deferred_from_coro(o):
    """Converts a coroutine into a Deferred, or returns the object as is if it isn't a coroutine"""
    if isinstance(o, defer.Deferred):
        return o
    if _isfuture(o) or inspect.isawaitable(o):
        if not is_asyncio_reactor_installed():
            # wrapping the coroutine directly into a Deferred, this doesn't work correctly with coroutines
            # that use asyncio, e.g. "await asyncio.sleep(1)"
            return defer.ensureDeferred(o)
        else:
            # wrapping the coroutine into a Future and then into a Deferred, this requires AsyncioSelectorReactor
            return defer.Deferred.fromFuture(asyncio.ensure_future(o))
    return o
Beispiel #2
0
def log_scrapy_info(settings):
    logger.info("Scrapy %(version)s started (bot: %(bot)s)", {
        'version': scrapy.__version__,
        'bot': settings['BOT_NAME']
    })
    logger.info(
        "Versions: %(versions)s", {
            'versions':
            ", ".join("%s %s" % (name, version)
                      for name, version in scrapy_components_versions()
                      if name != "Scrapy")
        })
    if is_asyncio_reactor_installed():
        logger.debug("Asyncio reactor is installed")
Beispiel #3
0
 def _handle_asyncio_reactor(self):
     if self.settings.getbool('ASYNCIO_REACTOR') and not is_asyncio_reactor_installed():
         raise Exception("ASYNCIO_REACTOR is on but the Twisted asyncio "
                         "reactor is not installed.")
Beispiel #4
0
 def test_is_asyncio_reactor_installed(self):
     # the result should depend only on the pytest --reactor argument
     self.assertEqual(is_asyncio_reactor_installed(),
                      self.reactor_pytest == 'asyncio')