    

 ## On this page

  

 

 # shared\_memory\_image\_client\_python.c File Reference

 Last update: 16.07.2025 

`#include <Python.h>`  
`#include "<a class="el" href="shared__memory__image__client__priv_8h_source.xhtml">shared_memory_image_client_priv.h</a>"`  


[Go to the source code of this file.](shared__memory__image__client__python_8c_source.xhtml)

## <a id="define-members" name="define-members"></a>Macros

\#define [MAX\_STREAMS](shared__memory__image__client__python_8c.xhtml#a4a1e12ec49840b798c6413a8f6c947a9) 50 ## <a id="func-members" name="func-members"></a>Functions

stream\_id [stream\_create](shared__memory__image__client__python_8c.xhtml#a68584fd5e8630714c738fc30ad19fa03) (str filename, int options=[IMAGESTREAM\_OPTIONS\_NONE](shared__memory__image__client_8h.xhtml#a7fbe522f7a46875a755f07c8ff69e2df)) frame [stream\_lock](shared__memory__image__client__python_8c.xhtml#ac78db99f06d47f7718fdcac4ae3cc374) (stream\_id id) [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) [stream\_unlock](shared__memory__image__client__python_8c.xhtml#a233ea80003a929e8e60aabd26a3b5c5e) (stream\_id id) [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) [stream\_destroy](shared__memory__image__client__python_8c.xhtml#af656cd2bf739307f1d52221d49da37ae) (stream\_id id) [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) [stream\_putframe](shared__memory__image__client__python_8c.xhtml#a23b3d9929aaff2a388402452ce5228c1) (stream\_id id, int width, int height, int framenumber, bytes pixeldata) <a id="details" name="details"></a>## Detailed Description

AuthorRandy Frank ([randy.nosp@m..fra.nosp@m.nk@an.nosp@m.sys..nosp@m.com](#)) Version1.0# <a class="anchor" id="ensight_grpc_shmem"></a>ensight\_grpc\_shmem python module

This module implements a set of Python bindings to the shared memory image transport API.

A simple example exercising the API might be:

import ensight_grpc_shmem

import time

 

def run_server(dx=1920, dy=1080, n=500):

 s = ensight_grpc_shmem.stream_create("shmem.bin", ensight_grpc_shmem.IMAGESTREAM_OPTIONS_SERVER)

 img = b'\\0'*dx*dy*3

 for i in range(n):

 time.sleep(1./60.)

 err = ensight_grpc_shmem.stream_putframe(s, dx, dy, i, img)

 print("Frame: {} {}".format(i, err))

 if i == 0:

 time.sleep(5)

 ensight_grpc_shmem.stream_destroy(s)

 

def run_client(num=200):

 c = ensight_grpc_shmem.stream_create("shmem.bin")

 count = 0

 while True:

 img = ensight_grpc_shmem.stream_lock(c)

 if type(img) is dict:

 print("Frame: {} {} {} {}".format(img['framenumber'], img['width'], img['height'],count))

 ensight_grpc_shmem.stream_unlock(c)

 count += 1

 if count &gt; num:

 break

 ensight_grpc_shmem.stream_destroy(c)



Definition in file [shared\_memory\_image\_client\_python.c](shared__memory__image__client__python_8c_source.xhtml).



## Macro Definition Documentation

<a id="a4a1e12ec49840b798c6413a8f6c947a9" name="a4a1e12ec49840b798c6413a8f6c947a9"></a>## [◆ ](#a4a1e12ec49840b798c6413a8f6c947a9)MAX\_STREAMS

 \#define MAX\_STREAMS 50

the maximum number of active streams we allow

Definition at line [30](shared__memory__image__client__python_8c_source.xhtml#l00030) of file [shared\_memory\_image\_client\_python.c](shared__memory__image__client__python_8c_source.xhtml).





## Function Documentation

<a id="a68584fd5e8630714c738fc30ad19fa03" name="a68584fd5e8630714c738fc30ad19fa03"></a>## [◆ ](#a68584fd5e8630714c738fc30ad19fa03)stream\_create()

 stream\_id stream\_create  ( str  *filename*,    int  *options* = `<a class="el" href="shared__memory__image__client_8h.xhtml#a7fbe522f7a46875a755f07c8ff69e2df">IMAGESTREAM_OPTIONS_NONE</a>`   ) 

Create a shared memory image stream.

Python wrapper for [SharedMemoryImageStream\_create()](shared__memory__image__client_8h.xhtml#a03ba052ae823b3e39fef153db8f03ea2 "SharedMemoryImageStream_create create a stream client instance."). Function in the [ensight\_grpc\_shmem python module](shared__memory__image__client__python_8c.xhtml#ensight_grpc_shmem) Python module.

See also[SharedMemoryImageStream\_create()](shared__memory__image__client_8h.xhtml#a03ba052ae823b3e39fef153db8f03ea2 "SharedMemoryImageStream_create create a stream client instance."). Parameters filenamethe name of the shared memory file to use. optionsthe stream creation options Exceptions IMAGESTREAM\_BAD\_ARGSIMAGESTREAM\_BAD\_FILE\_SIZEIMAGESTREAM\_UNABLE\_TO\_OPEN\_FILEIMAGESTREAM\_UNABLE\_TO\_MAP\_FILEIMAGESTREAM\_MEMORY\_ALLOC\_ERRORIMAGESTREAM\_THREAD\_CREATE\_ERRORReturnsthe allocated stream id. 



<a id="af656cd2bf739307f1d52221d49da37ae" name="af656cd2bf739307f1d52221d49da37ae"></a>## [◆ ](#af656cd2bf739307f1d52221d49da37ae)stream\_destroy()

 [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) stream\_destroy  ( stream\_id  *id*) 

Close down and destroy a shared memory transport interface.

Python wrapper for [SharedMemoryImageStream\_destroy()](shared__memory__image__client_8h.xhtml#a4ea47b6bda387b71ed5f91db329eff65 "SharedMemoryImageStream_destroy destroy a stream interface, releasing its resources."). Function in the [ensight\_grpc\_shmem python module](shared__memory__image__client__python_8c.xhtml#ensight_grpc_shmem) Python module.

See also[SharedMemoryImageStream\_destroy()](shared__memory__image__client_8h.xhtml#a4ea47b6bda387b71ed5f91db329eff65 "SharedMemoryImageStream_destroy destroy a stream interface, releasing its resources.").   
Parameters idthe stream to be destroyed. Exceptions IMAGESTREAM\_BAD\_ARGSReturnsIMAGESTREAM\_NOERROR 



<a id="ac78db99f06d47f7718fdcac4ae3cc374" name="ac78db99f06d47f7718fdcac4ae3cc374"></a>## [◆ ](#ac78db99f06d47f7718fdcac4ae3cc374)stream\_lock()

 frame stream\_lock  ( stream\_id  *id*) 

Get any available image frame.

Python wrapper for [SharedMemoryImageStream\_lock()](shared__memory__image__client_8h.xhtml#afefb8f5297147640b46d1f9eb1e77c9e "SharedMemoryImageStream_lock get a frame of pixels from the server."). Function in the [ensight\_grpc\_shmem python module](shared__memory__image__client__python_8c.xhtml#ensight_grpc_shmem) Python module.

See also[SharedMemoryImageStream\_lock()](shared__memory__image__client_8h.xhtml#afefb8f5297147640b46d1f9eb1e77c9e "SharedMemoryImageStream_lock get a frame of pixels from the server.").   
Parameters idthe stream to read from. Exceptions IMAGESTREAM\_BAD\_ARGSIMAGESTREAM\_IS\_SERVERIMAGESTREAM\_LOCKEDReturnsSharedMemoryImageError if no images are read or a dictionary with the same fields as [\_SharedMemoryFrame](struct___shared_memory_frame.xhtml). 



<a id="a23b3d9929aaff2a388402452ce5228c1" name="a23b3d9929aaff2a388402452ce5228c1"></a>## [◆ ](#a23b3d9929aaff2a388402452ce5228c1)stream\_putframe()

 [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) stream\_putframe  ( stream\_id  *id*,    int  *width*,    int  *height*,    int  *framenumber*,    bytes  *pixeldata*   ) 

Push an image into the shared memory transport buffer.

Python wrapper for [SharedMemoryImageStream\_putframe()](shared__memory__image__client__priv_8h.xhtml#abe3cb5374af97eeccf691864f6e2b2ad "SharedMemoryImageStream_putframe push a new image into a server image stream channel."). Only used by server connections. Function in the [ensight\_grpc\_shmem python module](shared__memory__image__client__python_8c.xhtml#ensight_grpc_shmem) Python module.

See also[SharedMemoryImageStream\_putframe()](shared__memory__image__client__priv_8h.xhtml#abe3cb5374af97eeccf691864f6e2b2ad "SharedMemoryImageStream_putframe push a new image into a server image stream channel.").   
Parameters idthe stream to write to. widthwidth of the frame in pixels heightheight of the frame in pixels framenumberthe sequence number of this frame pixeldataa bytes() object of at least width\*height\*3 bytes in size Exceptions IMAGESTREAM\_BAD\_ARGSIMAGESTREAM\_IS\_NOTSERVERIMAGESTREAM\_FRAME\_TOO\_LARGEReturnsSharedMemoryImageError IMAGESTREAM\_UNCONNECTED, IMAGESTREAM\_NO\_BUFFERAVAILABLE, IMAGESTREAM\_NOERROR 



<a id="a233ea80003a929e8e60aabd26a3b5c5e" name="a233ea80003a929e8e60aabd26a3b5c5e"></a>## [◆ ](#a233ea80003a929e8e60aabd26a3b5c5e)stream\_unlock()

 [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) stream\_unlock  ( stream\_id  *id*) 

Unlock the frame allocated by [stream\_lock()](shared__memory__image__client__python_8c.xhtml#ac78db99f06d47f7718fdcac4ae3cc374 "Get any available image frame.").

Python wrapper for [SharedMemoryImageStream\_unlock()](shared__memory__image__client_8h.xhtml#ac885e449551afd5fb5a7f19c5ec785a6 "SharedMemoryImageStream_unlock release a frame obtained by SharedMemoryImageStream_lock."). Function in the [ensight\_grpc\_shmem python module](shared__memory__image__client__python_8c.xhtml#ensight_grpc_shmem) Python module.

See also[SharedMemoryImageStream\_unlock()](shared__memory__image__client_8h.xhtml#ac885e449551afd5fb5a7f19c5ec785a6 "SharedMemoryImageStream_unlock release a frame obtained by SharedMemoryImageStream_lock.").   
Parameters idthe stream to read from. Exceptions IMAGESTREAM\_BAD\_ARGSIMAGESTREAM\_IS\_SERVERIMAGESTREAM\_NOT\_LOCKEDReturnsSharedMemoryImageError if no images are read or a dictionary with the same fields as [\_SharedMemoryFrame](struct___shared_memory_frame.xhtml).