为什么我的argparse系统出现系统出口2错误?

时间:2019-01-08 13:39:11

标签: python argparse word

这是我编码的主要部分。当我运行整个代码集时,它表明在此段中发生了异常:“ options = parse.parse_args()”处出现SystemExit2错误。我可以知道这里出了什么问题吗?

import argparse
import queue
import roypy
from sample_camera_info import print_camera_info
from roypy_sample_utils import CameraOpener, add_camera_opener_options
from roypy_platform_utils import PlatformHelper

class MyListener (roypy.IRecordStopListener):
   """A simple listener, in which waitForStop() blocks until onRecordingStopped has been called."""
   def __init__ (self):
       super (MyListener, self).__init__()
       self.queue = queue.Queue()

   def onRecordingStopped (self, frameCount):
       self.queue.put (frameCount)

   def waitForStop (self):
       frameCount = self.queue.get()
       print ("Stopped after capturing {frameCount} frames".format (frameCount=frameCount))

def main ():
    platformhelper = PlatformHelper() 
    parser = argparse.ArgumentParser (usage = __doc__)
    add_camera_opener_options (parser)
    parser.add_argument ("--frames", type=int, required=True, help="duration to capture data (number of frames)")
    parser.add_argument ("--output", type=str, required=True, help="filename to record to")
    parser.add_argument ("--skipFrames", type=int, default=0, help="frameSkip argument for the API method")
    parser.add_argument ("--skipMilliseconds", type=int, default=0, help="msSkip argument for the API method")
    options = parser.parse_args()

    opener = CameraOpener (options)
    cam = opener.open_camera ()

    print_camera_info (cam)

    l = MyListener()
    cam.registerRecordListener(l)
    cam.startCapture()
    cam.startRecording (options.output, options.frames, options.skipFrames, options.skipMilliseconds)

    seconds = options.frames * (options.skipFrames + 1) / cam.getFrameRate()
    if options.skipMilliseconds:
        timeForSkipping = options.frames * options.skipMilliseconds / 1000
        seconds = int (max (seconds, timeForSkipping))

    print ("Capturing with the camera running at {rate} frames per second".format (rate=cam.getFrameRate()))
    print ("This is expected to take around {seconds} seconds".format (seconds=seconds))

    l.waitForStop()

    cam.stopCapture()

   if (__name__ == "__main__"):
       main()

这是我执行死刑的回溯:

发生异常:SystemExit 2

文件“ C:\ Users \ NPStudent \ Desktop \ Python代码\ sample_record_rrf.py”,主行中的第44行     选项= parser.parse_args()

文件“ C:\ Users \ NPStudent \ Desktop \ Python Code \ sample_record_rrf.py”,第69行,在     main()

这是我运行程序时的命令行: enter image description here

1 个答案:

答案 0 :(得分:0)

您有一些必需的参数(required=True)丢失了!您发布的图片清楚地表明了这一点。

在VSCode中命中F5也会在不带参数的情况下运行它。产生相同的错误,进而导致VSCode抱怨您的脚本崩溃了。

您必须使用参数--frames--output来调用程序。 首先在命令行上尝试,然后为VSCode创建一个launch configuration

相关问题