Ctrl-C不会由于线程问题杀死我的python代码 - python

我正在使用Flask作为本地服务器并启动一个新线程:

rospy.init_node('path_planner')

当我在主线程上启动此线程时,按Ctrl-C时没有任何反应,我必须使用kill -9手动终止该进程

我曾尝试signal_handler,但仍然无法终止我的程序。

这是我经常使用的POST方法代码:

app = Flask(__name__)
app.config["MONGO_URI"] = "mongodb://ed:[email protected]:2325/test"

mongo = PyMongo(app)

@app.route('/goal', methods=['POST'])
def add_goal():
    goal = mongo.db.goal
    position = request.json['position']
    orientation = request.json['orientation']
    goal_id = goal.insert({'position' : position, 'orientation' : 
orientation})
    new_goal = goal.find_one({'_id' : goal_id})
    output = {'position' : new_goal['position'], 'orientation' : 
new_goal['orientation']}
    position_x = json.loads(position['x'])
    position_y = json.loads(position['y'])

    return jsonify(output)

这是我的主要内容:

if __name__ == '__main__':
    rospy.init_node("path_planner")
    app.run(debug=True)

当我运行代码时,flask服务器启动,并且一切正常,POST方法完成了它的工作。但是,当我完成并需要退出程序时,我按了Ctrl-C,但是似乎什么也没有发生。

参考方案

尝试按break按钮。我认为这会破坏过程。

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…

Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

Python ThreadPoolExecutor抑制异常 - python

from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…

如何用'-'解析字符串到节点js本地脚本? - python

我正在使用本地节点js脚本来处理字符串。我陷入了将'-'字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…