Search before asking
Apache SkyWalking Component
Python Agent (apache/skywalking-python)
What happened
When using gunicorn to start the service, subprocess.Popen executes the shell, and the python app-py file gets stuck and timeout occurs when running in the shell
def run_shell_and_wait(cmd: str, wait_time=None):
print(f"Running command: {cmd}")
process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
print(f"Waiting for command to finish with timeout: {wait_time}")
exit_code = process.wait(timeout=wait_time)
print(f"Command finished with exit code: {exit_code}")
return exit_code
!#/bin/sh
echo "Running tests..."
python $1
echo "Done."
What you expected to happen
import subprocess
from flask import Flask, request, jsonify
import pydevd_pycharm
pydevd_pycharm.settrace('localhost', port=5678, stdout_to_server=True, stderr_to_server=True)
app = Flask(name)
def run_shell_and_wait(cmd: str, wait_time=None):
print(f"Running command: {cmd}")
process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
print(f"Waiting for command to finish with timeout: {wait_time}")
exit_code = process.wait(timeout=wait_time)
print(f"Command finished with exit code: {exit_code}")
return exit_code
@app.route('/run-shell')
def run_shell_command():
cmd = request.args.get('command')
timeout = request.args.get('timeout', None, type=int)
if not cmd:
return jsonify({"error": "Missing 'command' parameter"}), 400
try:
exit_code = run_shell_and_wait(cmd, timeout)
return jsonify({
"status": "completed",
"exit_code": exit_code,
"message": f"Command executed with exit code {exit_code}"
})
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/health')
def health_check():
return jsonify({"status": "healthy"}), 200
if name == 'main':
app.run(host='0.0.0.0', port=8000, debug=True)
How to reproduce
sw-python run -p gunicorn -w 1 -b 0.0.0.0:8000 wsgi:app
http://localhost:8000/run-shell?command=sh%20test.sh%20test.py
Anything else
No response
Are you willing to submit a pull request to fix on your own?
Code of Conduct
Search before asking
Apache SkyWalking Component
Python Agent (apache/skywalking-python)
What happened
When using gunicorn to start the service, subprocess.Popen executes the shell, and the python app-py file gets stuck and timeout occurs when running in the shell
def run_shell_and_wait(cmd: str, wait_time=None):
print(f"Running command: {cmd}")
process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
print(f"Waiting for command to finish with timeout: {wait_time}")
exit_code = process.wait(timeout=wait_time)
print(f"Command finished with exit code: {exit_code}")
return exit_code
!#/bin/sh
echo "Running tests..."
python $1
echo "Done."
What you expected to happen
import subprocess
from flask import Flask, request, jsonify
import pydevd_pycharm
pydevd_pycharm.settrace('localhost', port=5678, stdout_to_server=True, stderr_to_server=True)
app = Flask(name)
def run_shell_and_wait(cmd: str, wait_time=None):
print(f"Running command: {cmd}")
process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
print(f"Waiting for command to finish with timeout: {wait_time}")
exit_code = process.wait(timeout=wait_time)
print(f"Command finished with exit code: {exit_code}")
return exit_code
@app.route('/run-shell')
def run_shell_command():
cmd = request.args.get('command')
timeout = request.args.get('timeout', None, type=int)
@app.route('/health')
def health_check():
return jsonify({"status": "healthy"}), 200
if name == 'main':
app.run(host='0.0.0.0', port=8000, debug=True)
How to reproduce
sw-python run -p gunicorn -w 1 -b 0.0.0.0:8000 wsgi:app
http://localhost:8000/run-shell?command=sh%20test.sh%20test.py
Anything else
No response
Are you willing to submit a pull request to fix on your own?
Code of Conduct