Skip to content

Commit 49d3a1e

Browse files
author
melihunsal
committed
windows perplexing failure fix
1 parent a5c8547 commit 49d3a1e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/prompt_based/model.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import logging
1212
import platform
13+
import threading
1314

1415
class BaseModel:
1516
"""
@@ -229,6 +230,10 @@ def __init__(self,openai_api_key):
229230
"""
230231
super().__init__(openai_api_key)
231232
self.streamlit_code_chain = LLMChain(llm=self.llm, prompt=streamlit_code_prompt)
233+
234+
def runThread(self,proc):
235+
proc.communicate()
236+
232237

233238
def run_code(self,code):
234239
"""
@@ -252,18 +257,14 @@ def run_code(self,code):
252257
env['STREAMLIT_SERVER_PORT'] = "8502"
253258
python_path = sys.executable
254259
process = subprocess.Popen([python_path,"-m","streamlit","run",tmp.name], env=env,stdout=PIPE, stderr=PIPE)
255-
timer = Timer(5, process.kill)
256-
try:
257-
timer.start()
258-
stdout, stderr = process.communicate()
259-
finally:
260-
timer.cancel()
260+
threading.Thread(target=self.runThread, args=(process,)).start()
261261
else:
262262
process = subprocess.Popen([streamlit_path,"run",tmp.name], env=environmental_variables,stdout=PIPE, stderr=PIPE)
263263
try:
264264
tmp.close()
265265
except PermissionError:
266266
pass
267+
267268
return process.pid
268269

269270
def __call__(self,topic, title, code, test_code,progress_func,success_func):

0 commit comments

Comments
 (0)