title: PiCamera cannot be initialized as a class member when the script is run from command prompt
body: <p>on my Raspberry Pi, I encounter a strange behaviour regarding the use of the PiCamera module. </p>
  
  <p>The following code runs smoothly when either started from IDLE (F5) or from the command prompt ($python test.py)</p>
  
  <pre><code>import picamera
  
  if __name__ == "__main__":
      camera=picamera.PiCamera()
      camera.close()
  </code></pre>
  
  <p>But when I put the camera object into a class the code will run only when started from IDLE (F5): </p>
  
  <pre><code>import picamera
  
  class VF:
      def __init__(self):
          self.camera = picamera.PiCamera()
  
      def __del__(self):
          self.camera.close()
  
  
  if __name__ == "__main__":
      myvf = VF()
  </code></pre>
  
  <p>When I start the above code from the command prompt, I get the following error message:</p>
  
  <blockquote>
    <p>mmal: mmal_vc_component_enable: failed to enable component: ENOSPC</p>
    
    <p>Traceback (most recent call last):   File "test.py", line 14, in
    
        myvf = VF()</p>
    
    <p>File "test.py", line 6, in <strong>init</strong>
        self.camera = picamera.PiCamera()</p>
    
    <p>File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line
    379, in <strong>init</strong>
        camera_num, self.STEREO_MODES[stereo_mode], stereo_decimate)</p>
    
    <p>File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line
    505, in _init_camera
        prefix="Camera component couldn't be enabled")</p>
    
    <p>File "/usr/lib/python2.7/dist-packages/picamera/exc.py", line 133,
    in mmal_check
        raise PiCameraMMALError(status, prefix)</p>
    
    <p>picamera.exc.PiCameraMMALError: Camera component couldn't be enabled:
    Out of resources (other than memory)</p>
  </blockquote>
  
  <p>The camera module is working correct, I just stripped the code down to the least possible size. Does anybody know this problem, or a similar problem, and can probably provide a solution? The Python Version is 2.7 and the Raspberry Rasbiab-System is completely up to date.
  Thanks in advance.</p>