Skip to content

Commit

Permalink
Enforce asyncio reactor in all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
elacuesta committed Jul 13, 2024
1 parent 848955e commit a65b661
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,14 @@ requests will be processed by the regular Scrapy download handler.

### Twisted reactor

When running on GNU/Linux or macOS you'll need to
[install the `asyncio`-based Twisted reactor](https://docs.scrapy.org/en/latest/topics/asyncio.html#installing-the-asyncio-reactor):
[Install the `asyncio`-based Twisted reactor](https://docs.scrapy.org/en/latest/topics/asyncio.html#installing-the-asyncio-reactor):

```python
# settings.py
TWISTED_REACTOR = "twisted.internet.asyncioreactor.AsyncioSelectorReactor"
```

This is not a requirement on Windows (see [Windows support](#windows-support))
This is the default in new projects since [Scrapy 2.7](https://github.com/scrapy/scrapy/releases/tag/2.7.0).


## Basic usage
Expand Down
4 changes: 1 addition & 3 deletions scrapy_playwright/handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import logging
import platform
from contextlib import suppress
from dataclasses import dataclass, field as dataclass_field
from ipaddress import ip_address
Expand Down Expand Up @@ -132,8 +131,7 @@ class ScrapyPlaywrightDownloadHandler(HTTPDownloadHandler):
def __init__(self, crawler: Crawler) -> None:
super().__init__(settings=crawler.settings, crawler=crawler)
_ThreadedLoopAdapter.start()
if platform.system() != "Windows":
verify_installed_reactor("twisted.internet.asyncioreactor.AsyncioSelectorReactor")
verify_installed_reactor("twisted.internet.asyncioreactor.AsyncioSelectorReactor")
crawler.signals.connect(self._engine_started, signals.engine_started)
self.stats = crawler.stats

Expand Down

0 comments on commit a65b661

Please sign in to comment.