Почему в моей системе argparse ошибка выхода из системы 2? - PullRequest
0 голосов
/ 08 января 2019

Это основная часть моего кодирования. Когда я запускаю весь набор моего кода, он показывает, что в этом сегменте произошла исключительная ситуация: ошибка SystemExit2 в "options = parse.parse_args ()". Могу ли я знать, что здесь пошло не так?

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 Code \ sample_record_rrf.py", строка 44, в основном options = parser.parse_args ()

Файл "C: \ Users \ NPStudent \ Desktop \ Python Code \ sample_record_rrf.py", строка 69, в Основной ()

Это командная строка, когда я запускаю программу: enter image description here

1 Ответ

0 голосов
/ 11 января 2019

У вас есть аргументы, которые указаны как обязательные (required=True), которые отсутствуют! Картинка, которую вы разместили, ясно показывает это.

Нажатие на F5 в VSCode также запустит его без аргументов. Выдает ту же ошибку, которая в свою очередь заставляет VSCode жаловаться на сбой вашего скрипта.

Вы должны вызывать вашу программу с аргументами --frames и --output. Сначала попробуйте в командной строке, а затем создайте конфигурацию запуска для VSCode.

...