javascript - 子进程被意外杀死而没有错误输出
问题描述
我正在开发一个心率传感器应用程序,其中读数存储在 CSV 文件中。移动应用程序通过蓝牙与 Raspberry pi 通信。我在 VSCode 上使用 ssh 在 Raspberry Pi 上进行开发。当 Python 代码直接运行时,会创建一个 CSV,传感器启动并保存读数。
但是,当我尝试将 python 代码作为 Javascript 中的子进程启动时,代码会在没有错误输出的情况下被终止之前创建 CSV 文件。此外,树莓派任务管理器中不会出现启动子进程创建的PID。
我需要代码工作,当在 BLE 应用程序上传递“1”时,python 进程开始并且读数存储在 CSV 中。
问题似乎与创建和写入 CSV 文件有关,因为我试图将该部分取出,以便将结果打印到控制台,并且效果很好。
Javascript:
function startLogging() {
if (! pythonProcess)
{
pythonProcess = spawn('python',["/home/pi/github/little_pulse/little_pulse/code/pulse_sensor/pulseWriter.py"]);
};
};
loggingCharacteristic.prototype.onWriteRequest = function(data,
offset, withoutResponse, callback) {
if(!offset) {
this._value = data;
}
console.log('loggingCharacteristic - onWriteRequest: value = ' +
this._value.slice(offset, offset + bleno.mtu).toString()
);
if( this._value == 1)
{
console.log('Logging Started');
sensor.startLogging();
}
else if(this._value == 2)
{
sensor.stopLogging();
console.log('Logging Stopped');
}
else {
console.log('Incorrect Input');
}
callback(this.RESULT_SUCCESS, this._value);
};
Python:
from pulsesensor2 import Pulsesensor
import csv
p = Pulsesensor()
with open('/home/pi/github/little_pulse/little_pulse/heartRateCSV.csv',n'a', newline='') as f:
theWriter = csv.writer(f)
theWriter.writerow(['Time','BPM','col3']) #column names
try:
p.startAsyncBPM()
while True:
#Code that prints bpm to console and writes to csv
except:
p.stopAsyncBPM()
解决方案
推荐阅读
- php - 如何通过 ajax 将数百万行从 DB 导出到 CSV?
- c# - 为什么我在内容页面上方看到 <%@ Page Title %> 标签
- sql - 如何编写动态查询以及如何在更远的查询中使用动态查询结果?
- excel - 粘贴为值
- javascript - 如何使用javascript更改多个div
- codeigniter - 如何与图像上传验证一起形成验证
- hadoop - 禁用 HDFS 的主机密钥检查?
- c# - 防止自引用表在 C# 中变为循环
- django-models - 我无法通过请求的用户使用 drf 序列化程序和 CreateAPIView 获取对象名称
- amazon-web-services - AWS Elastic Beanstalk 上发生的哪种事件会触发 SNS 通知?