Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

fix RuntimeError: Event loop is closed in windows

shenchuchengfcc9566f7939
diff --git a/metagpt/__init__.py b/metagpt/__init__.py
index b9c530d24..71ddd1aff 100644
--- a/metagpt/__init__.py
+++ b/metagpt/__init__.py
@@ -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
diff --git a/metagpt/_compat.py b/metagpt/_compat.py
new file mode 100644
index 000000000..e94a4d095
--- /dev/null
+++ b/metagpt/_compat.py
@@ -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
diff --git a/startup.py b/startup.py
index e6d5fc4e9..e2a903c9b 100644
--- a/startup.py
+++ b/startup.py
@@ -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)
-