Skip to content

Commit bd06481

Browse files
committed
Set WindowsProactorEventLoopPolicy after importing sk_function in python3.9+
1 parent 7da710e commit bd06481

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

metagpt/_compat.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
import sys
33
import warnings
44

5-
if sys.implementation.name == "cpython" and platform.system() == "Windows" and sys.version_info[:2] == (3, 9):
5+
if sys.implementation.name == "cpython" and platform.system() == "Windows":
66
import asyncio
7-
from asyncio.proactor_events import _ProactorBasePipeTransport
87

9-
from semantic_kernel.orchestration import sk_function as _ # noqa: F401
8+
if sys.version_info[:2] == (3, 9):
9+
from asyncio.proactor_events import _ProactorBasePipeTransport
1010

11-
# https://github.com/python/cpython/pull/92842
12-
def pacth_del(self, _warn=warnings.warn):
13-
if self._sock is not None:
14-
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
15-
self._sock.close()
11+
# https://github.com/python/cpython/pull/92842
12+
def pacth_del(self, _warn=warnings.warn):
13+
if self._sock is not None:
14+
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
15+
self._sock.close()
1616

17-
_ProactorBasePipeTransport.__del__ = pacth_del
17+
_ProactorBasePipeTransport.__del__ = pacth_del
1818

19-
# caused by https://github.com/microsoft/semantic-kernel/pull/1416
20-
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
19+
if sys.version_info >= (3, 9, 0):
20+
from semantic_kernel.orchestration import sk_function as _ # noqa: F401
21+
22+
# caused by https://github.com/microsoft/semantic-kernel/pull/1416
23+
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())

0 commit comments

Comments
 (0)