diff --git a/scrapy/__init__.py b/scrapy/__init__.py index bee059b0b..cb5e448b5 100644 --- a/scrapy/__init__.py +++ b/scrapy/__init__.py @@ -13,8 +13,7 @@ if sys.version_info < (2,5): sys.exit(1) # monkey patches to fix external library issues -from scrapy.xlib.patches import apply_patches -apply_patches() +from scrapy.xlib import twisted_250_monkeypatches # optional_features is a set containing Scrapy optional features optional_features = set() diff --git a/scrapy/xlib/patches.py b/scrapy/xlib/patches.py index 6c9c20d96..1395161c8 100644 --- a/scrapy/xlib/patches.py +++ b/scrapy/xlib/patches.py @@ -1,13 +1,9 @@ """ Monkey patches for supporting Twisted 2.5.0 + +NOTE: This module must not fail if twisted module is not available. """ -import twisted - -def apply_patches(): - if twisted.__version__ < '8.0.0': - add_missing_blockingCallFromThread() - # This function comes bundled with Twisted 8.x and above def add_missing_blockingCallFromThread(): import Queue @@ -42,3 +38,11 @@ def add_missing_blockingCallFromThread(): from twisted.internet import threads threads.blockingCallFromThread = blockingCallFromThread + +try: + import twisted + if twisted.__version__ < '8.0.0': + add_missing_blockingCallFromThread() +except ImportError: + pass +