Skip to content

Commit

Permalink
Merge pull request #97 from ethyca/restore-set-event-loop-helper
Browse files Browse the repository at this point in the history
Restore the `__set_event_loop()` helper
  • Loading branch information
PSalant726 authored Nov 2, 2022
2 parents 8117b4f + 0de610a commit 855dc54
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions fideslog/sdk/python/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=import-outside-toplevel, too-many-arguments

from asyncio import run
from sys import platform, version_info
from typing import Dict, Optional, Union

from aiohttp import (
Expand Down Expand Up @@ -71,6 +72,7 @@ def register(self, registration: Registration) -> None:
Register a new user.
"""

self.__set_event_loop()
run(self.send_async(registration))

async def register_async(self, registration: Registration) -> None:
Expand All @@ -85,6 +87,7 @@ def send(self, event: AnalyticsEvent) -> None:
Record a new analytics event.
"""

self.__set_event_loop()
run(self.send_async(event))

async def send_async(
Expand Down Expand Up @@ -169,3 +172,22 @@ def __get_analytics_payload(self, event: AnalyticsEvent) -> Dict:
payload[extra] = event_dict[extra]

return payload

@staticmethod
def __set_event_loop() -> None:
"""
Helps to work around a bug in the default Windows event loop for Python 3.8+
by changing the default event loop in Windows processes.
"""

if (
version_info[0] == 3
and version_info[1] >= 8
and platform.lower().startswith("win")
):
from asyncio import ( # type: ignore[attr-defined]
WindowsSelectorEventLoopPolicy,
set_event_loop_policy,
)

set_event_loop_policy(WindowsSelectorEventLoopPolicy())

0 comments on commit 855dc54

Please sign in to comment.