Skip to content

Commit 2b85ccd

Browse files
ai-libaimkarlelemillermicrosoft
authored
Python: Fix windows runtime error: adapt asyncio event loop policy for windows python 3.10 and above (#1416)
### Motivation and Context To fix a runtime error on windows for python version 3.10, 3.11 and above On windows, python version above 3.10.1, there will be a runtime error caused by asyncio event loop. add adapting code for windows when python version is above 3.10.1 to avoid the error. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Refer link: https://docs.python.org/3/library/asyncio-policy.html "Note In Python versions 3.10.9, 3.11.1 and 3.12 the [get_event_loop()](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop) method of the default asyncio policy emits a [DeprecationWarning](https://docs.python.org/3/library/exceptions.html#DeprecationWarning) if there is no running event loop and no current loop is set. In some future Python release this will become an error." Note: per testing, this error also occurred on python 3.10 below 3.10.9 Co-authored-by: Mark Karle <mkarle@users.noreply.github.com> Co-authored-by: Lee Miller <lemiller@microsoft.com>
1 parent e30229a commit 2b85ccd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

python/semantic_kernel/orchestration/sk_function.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) Microsoft. All rights reserved.
22

33
import asyncio
4+
import platform
5+
import sys
46
import threading
57
from enum import Enum
68
from logging import Logger
@@ -36,6 +38,9 @@
3638
)
3739
from semantic_kernel.utils.null_logger import NullLogger
3840

41+
if platform.system() == "Windows" and sys.version_info >= (3, 8, 0):
42+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
43+
3944

4045
class SKFunction(SKFunctionBase):
4146
"""

0 commit comments

Comments
 (0)