首页 > 解决方案 > 子进程被意外杀死而没有错误输出

问题描述

我正在开发一个心率传感器应用程序,其中读数存储在 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()

标签: javascriptpythoncsvbluetoothraspberry-pi

解决方案


推荐阅读