# Python example GEVServer backend list and send image

**URL:** <https://forum.commonvisionblox.com/t/python-example-gevserver-backend-list-and-send-image/1432>\
**Category:** Programming Questions\
**Tags:** acquisition, python, buffer\
**Created:** [June 25, 2021, 11:17am UTC](https://forum.commonvisionblox.com/t/python-example-gevserver-backend-list-and-send-image/1432 "2021-06-25T11:17:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASchmitt](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/aschmitt/32/827_2.png) [@ASchmitt](https://forum.commonvisionblox.com/u/ASchmitt)\
**Post date:** [June 25, 2021, 11:17am UTC](https://forum.commonvisionblox.com/t/python-example-gevserver-backend-list-and-send-image/1432/1 "2021-06-25T11:17:09Z")

</div>

![IMG Send](https://canada1.discourse-cdn.com/flex027/uploads/commonvisionblox/original/1X/760009070c8a676bdc314fbde1236ce34833f630.jpeg)

I have taken the part BackEnd.gev\_server\_stream.send(image, image\_release) “see red underlined” from the gevServer example. Here the method image\_release(img) is called, but nothing is passed to it, so I assumed that another constructor exists in the streaminghandler class, but this is not called when I delete the method image\_release(img), so I don’t understand which img is passed here.  
Second question why is the list in the back\_end needed, when the data from the device (in my case the CVMock.vin) could also be written directly into the RingBuffer of the initialised gevServer?

---

<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:** [June 25, 2021, 1:03pm UTC](https://forum.commonvisionblox.com/t/python-example-gevserver-backend-list-and-send-image/1432/2 "2021-06-25T13:03:16Z")

</div>

You register the image\_release callback so when the gev\_server decides to release the image, the callback is called with the image to be released.  
You should be able to use the managed ringbuffer when you don’t set the lockmode to on. In this mode, you need to manually handle the ring buffer images. The tutorial shows this to help understanding the ring buffer lock mode and the handling of images.

---

<div class="post-metadata">

**Author:** ![ASchmitt](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/aschmitt/32/827_2.png) [@ASchmitt](https://forum.commonvisionblox.com/u/ASchmitt)\
**Post date:** [June 28, 2021, 10:05am UTC](https://forum.commonvisionblox.com/t/python-example-gevserver-backend-list-and-send-image/1432/3 "2021-06-28T10:05:41Z")

</div>

I have changed the example and let the ring buffer switch automatically. So my question is more about why I need a list in the backend and why I need to call the method image\_release in the method send to “unlock” the list in the backend I tried it without the list and it doesn’t work. Also, I don’t understand why I need to pass a parameter to the image\_rlease method and where to pass it and when.

---

<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:** [June 28, 2021, 12:15pm UTC](https://forum.commonvisionblox.com/t/python-example-gevserver-backend-list-and-send-image/1432/4 "2021-06-28T12:15:36Z")

</div>

ok, let me try to explain.

- why a list in the backend? - The image list is like the ring buffer. It is only for handling the images. If you removed it, maybe check
  1. That the `self.stream.ring_buffer.lock_mode = cvb.RingBufferLockMode.Auto` is set or it is not set at all (prefer not setting it)  
2.That the `BackEnd.image_controller.refresh(image)` still refreshes on an image

- why call the method image\_release in the method send to “unlock” the list in the backend, why pass a parameter to the image\_release method, where to pass it and when?

I checked the doc and it seems that this specific part is missing in the python doc. I will see to it that we can get it in. If you take a look at the [GevServer Stream C++ doc](https://help.commonvisionblox.com/NextGen/14.0/cvbpp/d9/dc2/class_cvb_1_1_gev_server_1_1_stream.html#a38ab50648efc01e791e8ac10db653252) under _Send [1/3]_ the function takes an _image_ to send and an _imageReleased_ callback. This callback is a function you define which is called by the GevServer when the image was successfully sent and is not needed any more. This callback is defined directly before the _send_ call by

```auto
def image_release(img):
    img.unlock()
    BackEnd.img_list[BackEnd.buffer_index].unlock()
    print('Unlocked buffer at index ' + str(img.buffer_index))

```

The GevServer takes this function and after a successful send calls _image\_release_ with the successfully sent image as _img_ argument. You would then see to it that the image is unlocked so the ringbuffer can re-use the image again.

---

<div class="post-metadata">

**Author:** ![ASchmitt](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/aschmitt/32/827_2.png) [@ASchmitt](https://forum.commonvisionblox.com/u/ASchmitt)\
**Post date:** [June 28, 2021, 4:40pm UTC](https://forum.commonvisionblox.com/t/python-example-gevserver-backend-list-and-send-image/1432/5 "2021-06-28T16:40:38Z")

</div>

Okay, but as it looks, I don’t need to run the image so “img.unlock()”, because even without that, the images are sent normally. Only when I delete the list in the buffer does it no longer work. I had tried to optimise the method away completely, but that hasn’t worked so far.  
But if I now have to execute “img.unlock()” to release the image in the memory, I wonder why it works despite the missing code line.  
I also don’t use an “image\_controller” in my code and the “RingBufferLockMode” is set to Auto in my code.  
But I can try again to delete the list in the BackEnd and try to get it to run without it. But I’m afraid it won’t work.

---

<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:** [June 29, 2021, 6:17am UTC](https://forum.commonvisionblox.com/t/python-example-gevserver-backend-list-and-send-image/1432/6 "2021-06-29T06:17:34Z")

</div>

Maybe have a look at the C++ GevServer tutorial. It does not include the manual ring buffer management.
