# Acquire from multiple devices with CVBpy

**URL:** https://forum.commonvisionblox.com/t/acquire-from-multiple-devices-with-cvbpy/475
**Category:** Python API
**Tags:** acquisition
**Created:** [June 15, 2018, 2:46pm UTC](https://forum.commonvisionblox.com/t/acquire-from-multiple-devices-with-cvbpy/475 "2018-06-15T14:46:50Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![RBirkeland](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@RBirkeland](https://forum.commonvisionblox.com/u/RBirkeland)
#### Post date: [June 15, 2018, 2:46pm UTC](https://forum.commonvisionblox.com/t/acquire-from-multiple-devices-with-cvbpy/475/1 "2018-06-15T14:46:50Z")

</div>

@Andreas thanks for the guides.

But Im wondering, how can you get the stream of two (or more) cameras in python?

I’ve already successfully connected two cameras in the common vision manager, however using your example code I can only get the stream from the first camera.

Thanks.

---

<div class="post-metadata">

### Author: ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)
#### Post date: [June 19, 2018, 1:49pm UTC](https://forum.commonvisionblox.com/t/acquire-from-multiple-devices-with-cvbpy/475/2 "2018-06-19T13:49:38Z")

</div>

Hi @RBirkeland,

just use the optional parameters for open:

```python
device = cvb.DeviceFactory.open("GenICam.vin", port = 1)

```

This will open the second configured port.

An equivalent call would be:

```python
device = cvb.DeviceFactory.open_port("GenICam.vin", 1)

```

Please also note, that you cannot acquire images from more than one device asynchronously.  
This is due to the GIL (global interpreter lock), which does not allow real parallel execution. As a consequence the interpreter and all python threads block during a `stream.wait()` and cannot continue execution until this call returns.  
Currently, you must synchronize (e.g. via hardware trigger) all your cameras to acquire safely from multiple streams.

I’m currently working on a solution that offers true asynchronous acquisition through native threads. As soon as it is available I will introduce it in _Getting Started with CVBpy_.

---

<div class="post-metadata">

### Author: ![efrick](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@efrick](https://forum.commonvisionblox.com/u/efrick)
#### Post date: [November 25, 2020, 3:52pm UTC](https://forum.commonvisionblox.com/t/acquire-from-multiple-devices-with-cvbpy/475/3 "2020-11-25T15:52:19Z")

</div>

hi,  
i try to grab images from two cameras in two separate processes.  
in Process 1 i use:

device = cvb.DeviceFactory.open(os.path.join(cvb.install\_path(), “drivers”, “GenICam.vin”), port=0)

in Process 2 i use:

device = cvb.DeviceFactory.open(os.path.join(cvb.install\_path(), “drivers”, “GenICam.vin”), port=1)

but i allways get an error by start second process:

device = cvb.DeviceFactory.open(os.path.join(cvb.install\_path(), “drivers”, “GenICam.vin”), port=1)  
RuntimeError: {C-API call failed} ({LoadImageFileW})

if i has only one process, i can access to cam1 by port 1 or cam 2 by port 2, but i can’t access both at same time! why?

---

<div class="post-metadata">

### Author: ![usernv](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/usernv/32/637_2.png) [@usernv](https://forum.commonvisionblox.com/u/usernv)
#### Post date: [November 25, 2020, 4:04pm UTC](https://forum.commonvisionblox.com/t/acquire-from-multiple-devices-with-cvbpy/475/4 "2020-11-25T16:04:42Z")

</div>

Hi,  
accessing the second (1) port loads the device at port 0 and then shifts the port to 1. You would need to change the order in which you open the devices. So first loading port 1 and then 0 should fix the problem.

---

<div class="post-metadata">

### Author: ![efrick](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@efrick](https://forum.commonvisionblox.com/u/efrick)
#### Post date: [November 26, 2020, 11:14am UTC](https://forum.commonvisionblox.com/t/acquire-from-multiple-devices-with-cvbpy/475/5 "2020-11-26T11:14:04Z")

</div>

so easy? i will try it tomorrow

so i simple do:

device\_A = cvb.DeviceFactory.open(os.path.join(cvb.install\_path(), “drivers”, “GenICam.vin”), port=1)  
device\_B = cvb.DeviceFactory.open(os.path.join(cvb.install\_path(), “drivers”, “GenICam.vin”), port=0)

thank you!

---

<div class="post-metadata">

### Author: ![efrick](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@efrick](https://forum.commonvisionblox.com/u/efrick)
#### Post date: [December 18, 2020, 11:55am UTC](https://forum.commonvisionblox.com/t/acquire-from-multiple-devices-with-cvbpy/475/6 "2020-12-18T11:55:54Z")

</div>

Hi,  
i fixed the problem.

- changing ports didn’t helped
- behind start of first multiprocess _time.sleep(5)_ waiting for finishing first connecting helped to connect to both cameras.

---

<div class="post-metadata">

### Author: ![parsd](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/parsd/32/7_2.png) [@parsd](https://forum.commonvisionblox.com/u/parsd)
#### Post date: [December 30, 2020, 8:55am UTC](https://forum.commonvisionblox.com/t/acquire-from-multiple-devices-with-cvbpy/475/7 "2020-12-30T08:55:15Z")

</div>

To work around that problem we added the device discovery. This doesn’t use the GenICam.ini anymore. This only opens the device you want not interfering with other processes.

[https://forum.commonvisionblox.com/t/discover-camera-and-check-this-connection-state/536/4?u=parsd](https://forum.commonvisionblox.com/t/discover-camera-and-check-this-connection-state/536/4)
