Re:Show HN: Python 3.5 Async Web Crawler Example
by takeda on Tuesday March 22, 2016 @11:49AM
(#11337414)
I don't know scrapy enough to understand your first problem.
As for the second one, wouldn't using streams to process the data solve the memory usage issue?
Re:Show HN: Python 3.5 Async Web Crawler Example
by kmike84 on Tuesday March 22, 2016 @01:09PM
(#11338025)
The first problem is not specific to Scrapy; it is the same if you're using inlineCallbacks from twisted, tornado.gen or async def: there is no way to serialize tasks inside coroutine and save them to disk, e.g. to be able to stop the process and then restart it from the same point, or to avoid keeping the whole request queue in memory.
Stream processing could fix the second problem, but it is not a practical solution: in most cases one needs to build HTML tree in memory to do further processing (e.g. extract links). I'm also not aware of streaming regex libraries.
There are 2 challenges with async def I don't know how to solve elegantly:
1. how to integrate coroutine-based scraping code with on-disk persistent request queues;
2. how to deallocate resources without boilerplate in coroutine-based scraping code.
(1) is easier with callbacks-as-methods because this way state is passed explicitly (it is not in local variables), so Scrapy can choose to save it to disk.
Example of (2) is this code:
If anyone has suggestions please comment on https://github.com/scrapy/scrapy/issues/1144#issuecomment-14....