Skip to content

Commit

Permalink
Revert "Remove __set_event_loop()"
Browse files Browse the repository at this point in the history
This reverts commit fb90bdd.
  • Loading branch information
PSalant726 committed Nov 2, 2022
1 parent 8117b4f commit 601a99b
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 All @@ -23,6 +24,25 @@
REQUIRED_HEADERS = {"X-Fideslog-Version": __version__}


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())


class AnalyticsClient:
"""
An instance of a fides tool that wishes to send
Expand Down Expand Up @@ -71,6 +91,7 @@ def register(self, registration: Registration) -> None:
Register a new user.
"""

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

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

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

async def send_async(
Expand Down

0 comments on commit 601a99b

Please sign in to comment.