Skip to content

Commit

Permalink
fix: set_event_loop_policy for win32
Browse files Browse the repository at this point in the history
See aio-libs/aiodns#86 for more information.
  • Loading branch information
tazlin committed Sep 23, 2024
1 parent 217b760 commit f6ff226
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/ai_horde_client/image/async_manual_client_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import asyncio
import sys
import time
from pathlib import Path

Expand Down Expand Up @@ -119,4 +120,7 @@ async def main(apikey: str = ANON_API_KEY) -> None:
)
args = parser.parse_args()

if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

asyncio.run(main(args.apikey))
4 changes: 4 additions & 0 deletions examples/ai_horde_client/image/async_simple_client_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import asyncio
from pathlib import Path
import sys

import aiohttp
from loguru import logger
Expand Down Expand Up @@ -161,5 +162,8 @@ async def async_simple_generate_example(apikey: str = ANON_API_KEY) -> None:
)
args = parser.parse_args()

if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

# Run the example.
asyncio.run(async_simple_generate_example(args.apikey))
4 changes: 4 additions & 0 deletions examples/ai_horde_client/text/async_text_generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import asyncio
from pathlib import Path
import sys

import aiofiles
import aiohttp
Expand Down Expand Up @@ -115,4 +116,7 @@ async def main(apikey: str) -> None:
)
args = parser.parse_args()

if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

asyncio.run(main(args.api_key))
1 change: 1 addition & 0 deletions horde_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _dev_env_var_warnings() -> None: # pragma: no cover

_dev_env_var_warnings()


from horde_sdk.consts import (
PAYLOAD_HTTP_METHODS,
HTTPMethod,
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import asyncio
import base64
import os
import pathlib
import sys

import pytest
from loguru import logger

os.environ["TESTS_ONGOING"] = "1"

if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

from horde_sdk.ai_horde_api.apimodels import ImageGenerateAsyncRequest, ImageGenerationInputPayload
from horde_sdk.generic_api.consts import ANON_API_KEY

Expand Down

0 comments on commit f6ff226

Please sign in to comment.