Reputation: 107
When I run my code it shows that in this segment, an exception has occured: SystemExit2 error at the options = parse.parse_args()
. May I know what went wrong here?
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()
This is the traceback of my execution:
Exception has occurred: SystemExit
2
File "C:\Users\NPStudent\Desktop\Python Code\sample_record_rrf.py", line 44, in main
options = parser.parse_args()
File "C:\Users\NPStudent\Desktop\Python Code\sample_record_rrf.py", line 69, in <module>
main()
This is the command line when i run the program:
Upvotes: 7
Views: 5196
Reputation: 9801
You have arguments that are specified as required (required=True
) which are missing! The picture you posted clearly shows this.
Hitting F5 in VSCode will run it without arguments as well. Producing the same error, which in turn causes VSCode to complain that your script crashed.
You have to call your program with the arguments --frames
and --output
.
First try it on the commandline, then create a launch configuration for VSCode.
Upvotes: 1