Skip to content

Thread exception while closing stream #111

@GuidoBartoli

Description

@GuidoBartoli

Hi,
I'm using imutils to capture video stream from a Pi Camera on a Raspberry 3 B+ with Raspbian.
I have a function processing the frames and everything works fine until I press CTRL+C to interrupt the script. In that case, sometimes I receive these errors:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/imutils/video/pivideostream.py", line 42, in update
    self.camera.close()
  File "/usr/local/lib/python2.7/dist-packages/picamera/camera.py", line 745, in close
    self._splitter.close()
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmalobj.py", line 2400, in close
    self.disconnect()
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmalobj.py", line 2439, in disconnect
    self.inputs[0].disconnect()
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmalobj.py", line 1311, in disconnect
    self.connection.close()
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmalobj.py", line 2161, in close
    super(MMALConnection, self).close()
TypeError: super() argument 1 must be type, not None

while sometimes I receive this different error:

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 315, in 'calling callback function'
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmalobj.py", line 1227, in wrapper
    self._pool.send_buffer(block=False)
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmalobj.py", line 1931, in send_buffer
    super(MMALPortPool, self).send_buffer(port, block, timeout)
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmalobj.py", line 1882, in send_buffer
    port.send_buffer(buf)
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmalobj.py", line 1166, in send_buffer
    prefix="cannot send buffer to port %s" % self.name)
  File "/usr/local/lib/python2.7/dist-packages/picamera/exc.py", line 183, in mmal_check
    if status != mmal.MMAL_SUCCESS:
AttributeError: 'NoneType' object has no attribute 'MMAL_SUCCESS'
Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 315, in 'calling callback function'
  File "/usr/local/lib/python2.7/dist-packages/picamera/mmalobj.py", line 1220, in wrapper
    buf = MMALBuffer(buf)
TypeError: 'NoneType' object is not callable
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/imutils/video/pivideostream.py", line 31, in update
    for f in self.stream:
  File "/usr/local/lib/python2.7/dist-packages/picamera/camera.py", line 1710, in capture_continuous
    encoder.close()
  File "/usr/local/lib/python2.7/dist-packages/picamera/encoders.py", line 431, in close
    self.stop()
  File "/usr/local/lib/python2.7/dist-packages/picamera/encoders.py", line 416, in stop
    self.parent._stop_capture(self.camera_port)
  File "/usr/local/lib/python2.7/dist-packages/picamera/camera.py", line 529, in _stop_capture
    port.params[mmal.MMAL_PARAMETER_CAPTURE] = False
AttributeError: 'NoneType' object has no attribute 'MMAL_PARAMETER_CAPTURE'

It seems related to the thread handling the stream in PiVideoStream, where some objects should not be None when they are called after the capture has been interrupted.

This is the outline of my script, where I need to do some cleanup and final stuff after the loop is interrupted.

# initialization
stream = VideoStream(usePiCamera=True).start()
try:
    while True:
        result = process(stream.read())
except KeyboardInterrupt:
    stream.stop()
    # CLEANUP CODE

Is there something I am missing?

Thanks in advance,
Best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions