From bb88a1d3f9749fe65ef0873c56c1186ae9df6e0d Mon Sep 17 00:00:00 2001 From: Tasha Upchurch Date: Sun, 10 Sep 2023 20:00:28 -0400 Subject: [PATCH] fix for module 'os' has no attribute 'setsid' on windows fix #41 --- chatdev/chat_env.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/chatdev/chat_env.py b/chatdev/chat_env.py index fe518813..de6d05d4 100644 --- a/chatdev/chat_env.py +++ b/chatdev/chat_env.py @@ -84,14 +84,34 @@ class ChatEnv: success_info = "The software run successfully without errors." try: - command = "cd {}; ls -l; python3 main.py;".format(directory) - process = subprocess.Popen(command, shell=True, preexec_fn=os.setsid, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + # check if we are on windows or linux + if os.name == 'nt': + command = "cd {} && dir && python main.py".format(directory) + process = subprocess.Popen( + command, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + creationflags=subprocess.CREATE_NEW_PROCESS_GROUP + ) + else: + command = "cd {}; ls -l; python3 main.py;".format(directory) + process = subprocess.Popen(command, + shell=True, + preexec_fn=os.setsid, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) time.sleep(3) return_code = process.returncode # Check if the software is still running if process.poll() is None: - os.killpg(os.getpgid(process.pid), signal.SIGTERM) + if "killpg" in dir(os): + os.killpg(os.getpgid(process.pid), signal.SIGTERM) + else: + os.kill(process.pid, signal.SIGTERM) + if return_code == 0: return False, success_info else: