Skip to content

Commit

Permalink
Move __set_event_loop() to the AnalyticsClient class
Browse files Browse the repository at this point in the history
  • Loading branch information
PSalant726 committed Nov 2, 2022
1 parent 601a99b commit 0de610a
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions fideslog/sdk/python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,6 @@
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 @@ -91,7 +72,7 @@ def register(self, registration: Registration) -> None:
Register a new user.
"""

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

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

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

async def send_async(
Expand Down Expand Up @@ -191,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 0de610a

Please sign in to comment.