fix RuntimeError: Event loop is closed in windows

This commit is contained in:
shenchucheng 2023-09-18 22:37:54 +08:00
parent 5415ea4a8c
commit fcc9566f79
3 changed files with 37 additions and 17 deletions

View file

@ -1,5 +1,7 @@
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023/4/24 22:26
# @Author : alexanderwu
# @File : __init__.py
from metagpt import _compat as _ # noqa: F401

15
metagpt/_compat.py Normal file
View file

@ -0,0 +1,15 @@
import platform
import sys
import warnings
if sys.implementation.name == "cpython" and platform.system() == "Windows" and sys.version_info[:2] == (3, 9):
# https://github.com/python/cpython/pull/92842
from asyncio.proactor_events import _ProactorBasePipeTransport
def pacth_del(self, _warn=warnings.warn):
if self._sock is not None:
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
self._sock.close()
_ProactorBasePipeTransport.__del__ = pacth_del

View file

@ -1,11 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import platform
import fire
from metagpt.roles import Architect, Engineer, ProductManager
from metagpt.roles import ProjectManager, QaEngineer
from metagpt.roles import (
Architect,
Engineer,
ProductManager,
ProjectManager,
QaEngineer,
)
from metagpt.software_company import SoftwareCompany
@ -15,15 +20,17 @@ async def startup(
n_round: int = 5,
code_review: bool = False,
run_tests: bool = False,
implement: bool = True
implement: bool = True,
):
"""Run a startup. Be a boss."""
company = SoftwareCompany()
company.hire([
ProductManager(),
Architect(),
ProjectManager(),
])
company.hire(
[
ProductManager(),
Architect(),
ProjectManager(),
]
)
# if implement or code_review
if implement or code_review:
@ -46,7 +53,7 @@ def main(
n_round: int = 5,
code_review: bool = True,
run_tests: bool = False,
implement: bool = True
implement: bool = True,
):
"""
We are a software startup comprised of AI. By investing in us,
@ -58,12 +65,8 @@ def main(
:param code_review: Whether to use code review.
:return:
"""
if platform.system() == "Windows":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(startup(idea, investment, n_round,
code_review, run_tests, implement))
asyncio.run(startup(idea, investment, n_round, code_review, run_tests, implement))
if __name__ == '__main__':
if __name__ == "__main__":
fire.Fire(main)