mirror of https://github.com/scrapy/scrapy.git
Install the asyncio reactor on "import scrapy".
This commit is contained in:
parent
1b35260625
commit
1b437bbe9f
|
|
@ -23,6 +23,28 @@ import warnings
|
|||
warnings.filterwarnings('ignore', category=DeprecationWarning, module='twisted')
|
||||
del warnings
|
||||
|
||||
# Install twisted asyncio loop
|
||||
def _install_asyncio_reactor():
|
||||
global asyncio_supported
|
||||
try:
|
||||
import asyncio
|
||||
from twisted.internet import asyncioreactor
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
from twisted.internet.error import ReactorAlreadyInstalledError
|
||||
try:
|
||||
asyncioreactor.install(asyncio.get_event_loop())
|
||||
asyncio_supported = True
|
||||
except ReactorAlreadyInstalledError:
|
||||
import twisted.internet.reactor
|
||||
if isinstance(twisted.internet.reactor,
|
||||
asyncioreactor.AsyncioSelectorReactor):
|
||||
asyncio_supported = True
|
||||
asyncio_supported = False
|
||||
_install_asyncio_reactor()
|
||||
del _install_asyncio_reactor
|
||||
|
||||
# Apply monkey patches to fix issues in external libraries
|
||||
from . import _monkeypatches
|
||||
del _monkeypatches
|
||||
|
|
|
|||
Loading…
Reference in New Issue