Skip to content

Commit

Permalink
v0.0.3402
Browse files Browse the repository at this point in the history
  • Loading branch information
sanzenwin committed Apr 6, 2024
1 parent 2b44c4e commit 8a223e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion scrapy_playwright/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.3401"
__version__ = "0.0.3402"
29 changes: 9 additions & 20 deletions scrapy_playwright/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,29 @@

# Supporting for Windows
if sys.platform == "win32" and sys.version_info >= (3, 8):
import threading

class Var:
windows_loop = None
windows_thread = None

def windows_get_asyncio_event_loop():
if Var.windows_thread is None:
if Var.windows_loop is None:
Var.windows_loop = asyncio.WindowsProactorEventLoopPolicy().new_event_loop()
asyncio.set_event_loop(Var.windows_loop)
if not Var.windows_loop.is_running():
Var.windows_thread = threading.Thread(
target=Var.windows_loop.run_forever, daemon=True
)
Var.windows_thread.start()
return Var.windows_loop
from dektools.sync import EnvSet

class WindowsEnvSet(EnvSet):
event_loop_policy_cls = asyncio.WindowsProactorEventLoopPolicy

windows_env_set = WindowsEnvSet()

async def windows_get_result(o):
return asyncio.run_coroutine_threadsafe(o, windows_get_asyncio_event_loop()).result()
return windows_env_set.coroutine(o)

def deferred_from_coro(o):
if isinstance(o, Deferred):
return o
return deferred_from_coro_default(windows_get_result(o))

else:
windows_get_asyncio_event_loop = None
windows_env_set = None
windows_get_result = None
deferred_from_coro = deferred_from_coro_default

__all__ = [
"ScrapyPlaywrightDownloadHandler",
"windows_get_asyncio_event_loop",
"windows_env_set",
"windows_get_result",
]

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
install_requires=[
"scrapy>=2.0,!=2.4.0",
"playwright>=1.15",
"dektools<1.0.0",
],
)

0 comments on commit 8a223e0

Please sign in to comment.