Skip to content

Commit

Permalink
Python: Fix windows runtime error: adapt asyncio event loop policy fo…
Browse files Browse the repository at this point in the history
…r 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 <[email protected]>
Co-authored-by: Lee Miller <[email protected]>
  • Loading branch information
3 people authored Jun 16, 2023
1 parent e30229a commit 2b85ccd
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/semantic_kernel/orchestration/sk_function.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) Microsoft. All rights reserved.

import asyncio
import platform
import sys
import threading
from enum import Enum
from logging import Logger
Expand Down Expand Up @@ -36,6 +38,9 @@
)
from semantic_kernel.utils.null_logger import NullLogger

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


class SKFunction(SKFunctionBase):
"""
Expand Down

0 comments on commit 2b85ccd

Please sign in to comment.