简体   繁体   English

Python程序在一段时间后停止,Beaglebone黑色Debian

[英]Python program stops after sometime, Beaglebone black Debian

The program runs on beaglebone black (rev.C) debian using command prompt (PuTTY) seems to work for some 1-2h max then stops (=no data log) Tested with few minutes and it works fine but I have no idea why it would stop after a while even though The BBB is still running (at stable power supply) 该程序使用命令提示符(PuTTY)在beaglebone black(rev.C)debian上运行,最长可运行约1-2h,然后停止(=无数据记录)经过几分钟的测试,并且工作正常,但我不知道为什么即使BBB仍在运行(在稳定的电源下),它也会在一段时间后停止

Btw, any comment is appreciated. 顺便说一句,任何评论表示赞赏。 Any improvement recommendation is of great help. 任何改进建议都会有很大帮助。 It's clearly my first program ever 显然这是我的第一个程序

Update 01: full program code sample of latest behaviour: run 1h logging, 9 times. 更新01:最新行为的完整程序代码示例:运行1h日志记录,运行9次。 it stops logging after 2 hours (almost exact 2h) and that file yeilds "last edited" 2h after (eg stop logging at 3.00, last edited at 5.00) 它会在2小时(几乎是2小时)后停止记录,并且文件在2小时后“最后编辑”(例如,在3.00停止记录,在5.00结束编辑)

import Adafruit_BBIO.ADC as ADC
import Adafruit_BBIO.GPIO as GPIO
import time
import sys
sensor_00 = 'P9_33'
sensor_mk = 'P9_35'
pinLED = 'P9_41'
ADC.setup()
GPIO.setup(pinLED, GPIO.OUT)

print('Sensor reading test..........')+ "\n"
test_rw00 = ADC.read_raw(sensor_00)
test_rwmk = ADC.read_raw(sensor_mk)
print('Sensor 00: %s' %test_rw00) + "\n"
print('Sensor mk: %s'%test_rwmk )+ "\n"

LogTime = int(input("Data file logging interval (seconds):"))
delay = int(raw_input("Reading delay: "))
TestLocation = raw_input("Test location:")
TestSpecs = raw_input("Test scpecs/ purposes: ")
n = int(raw_input("Estimated amount of Data file:"))

def indicatingLED():
    GPIO.output(pinLED, GPIO.HIGH)
    time.sleep(3)
    GPIO.output(pinLED, GPIO.LOW)
    time.sleep(1)

def TestSpecs_txtWrite():
    datafile.write("Date and time of measurement:%s" % log_date_str+ "\n")
    datafile.write("Data file logging interval (seconds): %s" %LogTime + "\n")
    datafile.write("Test Location: %s" %TestLocation + "\n")
    datafile.write("Test specs/ purposes: %s" %TestSpecs + "\n")
    datafile.write("Test readings, sensors in position, elevator doesn't run: Sensor00: " + str(test_rw00) + ",    ")
    datafile.write("Sensor mk: " + str(test_rwmk) + "\n")
    datafile.write("-------------------------------------------------------"+"\n")


print('Sensor reading started...')+ "\n"

for i in xrange(1,n):
  t_end = time.time() + LogTime
  log_date_str = time.strftime("%Y%m%d_%H%M")
  datafile = open("%s.txt" %log_date_str,"w+")
  TestSpecs_txtWrite()
while time.time() < t_end:
  indicatingLED()
  val_rw_00 = ADC.read_raw(sensor_00)
  val_rw_mk = ADC.read_raw(sensor_mk)
  datafile.write("Vol_Sensor00:" + str(val_rw_00) +",     ")
  datafile.write("Vol_Sensormk:" + str(val_rw_mk)+"\n")
  time.sleep(delay)
log_date_str = time.strftime("%Y%m%d_%H%M")
datafile.write("Log ended at: %s" %log_date_str + "\n")
print('Measurement ended !-----------------------------------------------')

As you say you are disconnecting from the Board . 如您所说,您正在与董事会断开联系 This will after a connection timeout lead to the connection being reset and the program losing its controlling TTY . 在连接超时之后,这将导致连接被重置,并且程序将失去其控制TTY This will ultimately terminate the program and is expected behavior. 最终将终止程序,这是预期的行为。

You should explore things like: 您应该探索以下内容:

  • Append a & to make the process detach from the TTY 附加&以使过程脱离TTY
  • Look into nohup 看看nohup
  • Run it inside a terminal multiplexer like screen or tmux screentmux等终端多路复用器中tmux
  • Have the program itself go into 'background' by detaching itself from the controlling terminal. 通过使程序与控制终端分离,使程序本身进入“后台”状态。

There are still others like rc.local or a systemd service file. 还有其他类似rc.local或systemd服务文件的文件。 The above should be plenty enough of starting points for a simple solution though. 上面的内容应该足以作为一个简单的解决方案的起点。 A good book on basic Linux or embedded Linux systems would help too. 一本有关基本Linux或嵌入式Linux系统的好书也会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM