picamera2: [BUG] Using two instances on separate interfaces simultaneously can sometimes fail with "Camera in Configured state trying queueRequest() requiring state Running"

Describe the bug If you initialize two picamera2 objects on different interfaces, then attempt to take pictures with them back-to-back without closing them in-between, they can sometimes fail:

[0:38:03.430892329] [2855] ERROR Camera camera.cpp:533 Camera in Configured state trying queueRequest() requiring state Running

To Reproduce

  1. Spawn two picamera2 objects on separate interfaces
  2. start object one, take a picture, then stop it (but don’t explicitly call close())
  3. attempt to start object 2

– OR –

from picamera2 import Picamera2

def take_pictures(should_close_between=False):
    cam1 = Picamera2(0)
    cam2 = Picamera2(1)

    print('camera 1 seq')
    config1 = cam1.create_still_configuration()
    cam1.configure(config1)
    cam1.start()
    cam1.capture_file("sim_test_c1.jpg")
    cam1.stop()
    
    if should_close_between:
        print('closing camera 1')
        cam1.close()

    print('camera 2 seq')
    config2 = cam2.create_still_configuration()
    cam2.configure(config2)
    cam2.start()
    cam2.capture_file("sim_test_c2.jpg")
    cam2.stop()
    
    if not should_close_between:
        print('closing camera 1')
        cam1.close()
    print('closing camera 2')
    cam2.close()



print("########## taking two photos, this will work")
take_pictures(should_close_between=True)
print("########## taking two photos, this will fail")
take_pictures()

Expected behaviour It just works™ without having to close the object in between

Console Output, Screenshots

❯ python picamera2_sequential_test.py
########## taking two photos, this will work
[0:37:59.038259411] [2845]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3866-0c55e522
[0:37:59.069626442] [2846]  WARN RPI raspberrypi.cpp:1258 Mismatch between Unicam and CamHelper for embedded data usage!
[0:37:59.070797109] [2846]  INFO RPI raspberrypi.cpp:1374 Registered camera /base/soc/i2c0mux/i2c@0/imx219@10 to Unicam device /dev/media2 and ISP device /dev/media0
[0:37:59.078736837] [2846]  WARN RPI raspberrypi.cpp:1258 Mismatch between Unicam and CamHelper for embedded data usage!
[0:37:59.079869542] [2846]  INFO RPI raspberrypi.cpp:1374 Registered camera /base/soc/i2c0mux/i2c@1/imx219@10 to Unicam device /dev/media4 and ISP device /dev/media1
camera 1 seq
[0:37:59.085781209] [2845]  INFO Camera camera.cpp:1035 configuring streams: (0) 3280x2464-BGR888
[0:37:59.086328219] [2846]  INFO RPI raspberrypi.cpp:761 Sensor: /base/soc/i2c0mux/i2c@0/imx219@10 - Selected sensor format: 3280x2464-SBGGR10_1X10 - Selected unicam format: 3280x2464-pBAA
closing camera 1
camera 2 seq
[0:38:00.432455763] [2851]  INFO Camera camera.cpp:1035 configuring streams: (0) 3280x2464-BGR888
[0:38:00.432982440] [2846]  INFO RPI raspberrypi.cpp:761 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 3280x2464-SBGGR10_1X10 - Selected unicam format: 3280x2464-pBAA
closing camera 2
########## taking two photos, this will fail
camera 1 seq
[0:38:01.833862282] [2853]  INFO Camera camera.cpp:1035 configuring streams: (0) 3280x2464-BGR888
[0:38:01.841378369] [2846]  INFO RPI raspberrypi.cpp:761 Sensor: /base/soc/i2c0mux/i2c@0/imx219@10 - Selected sensor format: 3280x2464-SBGGR10_1X10 - Selected unicam format: 3280x2464-pBAA
camera 2 seq
[0:38:02.607401706] [2855]  INFO Camera camera.cpp:1035 configuring streams: (0) 3280x2464-BGR888
[0:38:02.608323303] [2846]  INFO RPI raspberrypi.cpp:761 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected sensor format: 3280x2464-SBGGR10_1X10 - Selected unicam format: 3280x2464-pBAA
[0:38:03.430892329] [2855] ERROR Camera camera.cpp:533 Camera in Configured state trying queueRequest() requiring state Running

Hardware : Compute Module 4, picamera2 0.3.3, bullseye, 2x imx219

Additional context This doesn’t always reproduce, but once it does it will consistently. I cannot figure out what makes that happen, seems very random.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Yes, this is in my plans. I’m busy with other stuff at the moment, and also on holiday at some point, so my guess would be that it’s “a few weeks away”.