繁体   English   中英

这是终止子流程的正确方法吗?

[英]Is this the right way to terminate subprocess?

我正在通过子过程使用arecord在树莓派中进行记录:按操纵杆按钮开始记录,再按一次按钮停止记录:我使用p.terminate()停止记录,这是我的代码。 我不知道这是终止子进程的正确方法吗?

提前致谢。

if joystick.get_numbuttons() >= 1 and joystick.get_button( 0 ) == 0 and    button_pressed:
button_pressed = False
is_recording = not is_recording
print(is_recording)

#start recording
if is_recording:
    dotting = dotting + 1
    #recording code
   datetime.now().strftime("%Y%m%d_%H%M%S")
    filename = "%s.wav" % datetime.now().strftime("%Y%m%d_%H%M%S")
    p=subprocess.Popen(['arecord', '--device=hw:1,0', '--format', 'S16_LE', '--rate', '44100-c1', filename], shell=False)

    #change background
    background = pygame.image.load(background_image2).convert()
    #start timer
    stopFlag = Event()
    timer = MyTimer(stopFlag,time.clock())
    #timer.start()
    text2 = font.render('.', True, BLACK)

    screen.blit(background, (0,0))

    stopFlag.set()

    #record, remaining here


#stop recording
else:
    #stop recording, save record
    timer.do_run = False
    backToPreviousQuestion()
    background = pygame.image.load(background_image).convert()
    p.terminate()

pygame.display.update()

从一般意义上讲, .terminate()是用于结束子.terminate()的正确方法。 您可以查看文档以获取更多信息: https : //docs.python.org/3.3/library/

暂无
暂无

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

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