fix python stdout and stderr integration
This commit is contained in:
@@ -60,6 +60,4 @@ class Server:
|
|||||||
port = port or 8900
|
port = port or 8900
|
||||||
with self.HTTPServer(("127.0.0.1", port), handler) as httpd:
|
with self.HTTPServer(("127.0.0.1", port), handler) as httpd:
|
||||||
print("serving at http://127.0.0.1:" + str(port))
|
print("serving at http://127.0.0.1:" + str(port))
|
||||||
import sys
|
|
||||||
sys.stdout.flush()
|
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|||||||
@@ -76,10 +76,11 @@ export default class AiPythonConnector {
|
|||||||
const port = await this.port();
|
const port = await this.port();
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
console.log('ai: starting python backend');
|
console.log('ai: starting python backend');
|
||||||
this.process = exec('. ../.venv/bin/activate && cd ../ai && python3 main.py --port ' + port);
|
this.process = exec('. ../.venv/bin/activate && cd ../ai && python3 main.py --port ' + port,
|
||||||
|
{env: {'PYTHONUNBUFFERED': '1'}});
|
||||||
|
|
||||||
this.process.stdout!.on('data', (data) => {
|
this.process.stdout!.on('data', (data) => {
|
||||||
console.log('ai: ' + data.toString());
|
console.log('ai: ' + data.toString().replace(/\r?\n$/, ''));
|
||||||
if (data.includes('' + port)) {
|
if (data.includes('' + port)) {
|
||||||
console.log('ai: python backend started');
|
console.log('ai: python backend started');
|
||||||
resolve();
|
resolve();
|
||||||
@@ -87,7 +88,7 @@ export default class AiPythonConnector {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.process.stderr!.on('data', (data) => {
|
this.process.stderr!.on('data', (data) => {
|
||||||
console.error('ai: ' + data.toString());
|
console.error('ai: ' + data.toString().replace(/\r?\n$/, ''));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.process.on('exit', (code) => {
|
this.process.on('exit', (code) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user