Created
February 20, 2013 16:10
-
-
Save artemdevel/4996685 to your computer and use it in GitHub Desktop.
SignalManager tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scrapy import signals | |
from scrapy.http import Request | |
from scrapy.spider import BaseSpider | |
from scrapy.signalmanager import SignalManager | |
class Test5(BaseSpider): | |
""" New SignalManager API test, doesn't work | |
""" | |
name = "test5" | |
start_urls = ["http://httpbin.org/status/200"] | |
def __init__(self, *args, **kwargs): | |
super(Test5, self).__init__(*args, **kwargs) | |
sm = SignalManager(self) | |
""" I also tried to iniatialize SignalManager this way: | |
sm = SignalManager() so dispatcher.Anonymous should be used | |
as a sender, but this didn't help either. | |
""" | |
sm.connect(self.idle_handler, signal=signals.spider_idle) | |
def parse(self, response): | |
self.log("Parse") | |
def idle_handler(self, spider): | |
self.log("Idle handler") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scrapy import signals | |
from scrapy.http import Request | |
from scrapy.spider import BaseSpider | |
from scrapy.xlib.pydispatch import dispatcher | |
class Test5_1(BaseSpider): | |
""" Old approach for signals in Scrapy | |
""" | |
name = "test5_1" | |
start_urls = ["http://httpbin.org/status/200"] | |
def __init__(self, *args, **kwargs): | |
super(Test5_1, self).__init__(*args, **kwargs) | |
dispatcher.connect(self.idle_handler, signal=signals.spider_idle) | |
def parse(self, response): | |
self.log("Parse") | |
def idle_handler(self, spider): | |
self.log("Idle handler") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scrapy import signals | |
from scrapy.http import Request | |
from scrapy.spider import BaseSpider | |
from scrapy.xlib.pydispatch import dispatcher | |
from scrapy.signalmanager import SignalManager | |
class Test5_2(BaseSpider): | |
""" Worked example for new SignalManager API | |
""" | |
name = "test5_2" | |
start_urls = ["http://httpbin.org/status/200"] | |
def __init__(self, *args, **kwargs): | |
super(Test5_2, self).__init__(*args, **kwargs) | |
SignalManager(dispatcher.Any).connect(self.idle_handler, signal=signals.spider_idle) | |
def parse(self, response): | |
self.log("Parse") | |
def idle_handler(self, spider): | |
self.log("Idle handler") |
Thank you! Signals connect sucks on the website indeed!
thanks, you saved my day !! nothing in the web, I confirm ! thanks again mate
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. The documentation (and the web) doesnt help to use signals - you did it!