Scrapy: non-blocking pause

前端 未结 3 1428
南方客
南方客 2021-01-31 10:31

I have a problem. I need to stop the execution of a function for a while, but not stop the implementation of parsing as a whole. That is, I need a non-blocking pause.

It

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 11:06

    If you're attempting to use this for rate limiting, you probably just want to use DOWNLOAD_DELAY instead.

    Scrapy is just a framework on top of Twisted. For the most part, you can treat it the same as any other twisted app. Instead of calling sleep, just return the next request to make and tell twisted to wait a bit. Ex:

    from twisted.internet import reactor, defer
    
    def non_stop_function(self, response)
        d = defer.Deferred()
        reactor.callLater(10.0, d.callback, Request(
            'some url',
            callback=self.non_stop_function
        ))
        return d
    

提交回复
热议问题