double-buffer-shared-memory-manager


Namedouble-buffer-shared-memory-manager JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/m-ghiani/DOUBLE_BUFFER_SHARED_MEMORY_MANAGER
SummaryPackage for communication with shared memory using double buffer
upload_time2024-01-03 04:09:48
maintainer
docs_urlNone
authorMassimo Ghiani
requires_python>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements colorlog numpy readerwriterlock
Travis-CI No Travis.
coveralls test coverage No coveralls.
            DoubleBufferedSharedMemoryManager
=================================

``DoubleBufferedSharedMemoryManager`` is a Python class designed to
manage double-buffered shared memory for concurrent read/write
operations, particularly suited for handling video frames stored 
as NumPy ndarrays.

Features
--------

-  **Double-Buffered Memory**: Allows one buffer to be read while the
   other is being written to, minimizing read-write conflicts.
-  **Thread-Safe Access**: Utilizes reader-writer locks to allow
   multiple readers and a single writer.
-  **Dynamic Memory Management**: Dynamically creates or connects to
   shared memory segments based on the provided base name.
-  **Customizable Data Handling**: Supports specifying the shape and
   data type of the NumPy ndarray.

Requirements
------------

-  Python 3.x
-  NumPy
-  multiprocessing
-  readerwriterlock
-  colorlog (for enhanced logging with color)

Installation
------------

Ensure you have the required libraries:

.. code:: bash

   pip install numpy readerwriterlock colorlog

Usage
-----

Initialization
~~~~~~~~~~~~~~

Import and initialize the manager:

.. code:: python

   from double_buffered_shared_memory import DoubleBufferedSharedMemoryManager
   import numpy as np

   # Initialize with default parameters
   manager = DoubleBufferedSharedMemoryManager('image_buffer')

   # Initialize with custom shape and dtype
   manager = DoubleBufferedSharedMemoryManager('image_buffer', shape=(576, 720, 3), dtype=np.uint16)

Writing to Shared Memory
~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

   # Create a random HD image
   img = np.random.randint(255, size=(1080, 1920, 3), dtype=np.uint8)

   # Write to the active buffer
   manager[0] = img

0 is a convention, you can use any number, but for clarity use 0

Reading from Shared Memory
~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

   # Switch the active buffer
   manager.__switch()

   # Read from the non-active buffer
   img_copy = manager[0]

0 is a convention, you can use any number, but for clarity use 0

Cleanup
~~~~~~~

It’s important to clean up shared memory resources when they’re no
longer needed:

.. code:: python

   manager.cleanup()

Using with Context Manager
~~~~~~~~~~~~~~~~~~~~~~~~~~

The class supports context management protocol for automatic resource
management:

.. code:: python

   with DoubleBufferedSharedMemoryManager('image_buffer') as manager:
       # Your code to use the manager
       pass

Logging
-------

The class utilizes ``colorlog`` for enhanced logging. Log messages will
vary in color based on the log level to provide a clearer and more
intuitive understanding of the operations and events.

Contributing
------------

Contributions, issues, and feature requests are welcome. Feel free to
check `issues page <https://github.com/your-repo/issues>`__ if you want
to contribute.

Author
------

Massimo Ghiani m.ghiani@gmail.com

License
-------

Distributed under the MIT License. See ``LICENSE`` for more information.

Acknowledgements
----------------

-  `NumPy <https://numpy.org/>`__
-  `readerwriterlock <https://pypi.org/project/readerwriterlock/>`__
-  `colorlog <https://pypi.org/project/colorlog/>`__

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/m-ghiani/DOUBLE_BUFFER_SHARED_MEMORY_MANAGER",
    "name": "double-buffer-shared-memory-manager",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "",
    "author": "Massimo Ghiani",
    "author_email": "m.ghiani@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/51/63/4bcfc9a2d506b55765015a4c5bf982e4fcb1f8fe9cbaf86dc2d3bcb4d64d/double-buffer-shared-memory-manager-1.0.3.tar.gz",
    "platform": null,
    "description": "DoubleBufferedSharedMemoryManager\n=================================\n\n``DoubleBufferedSharedMemoryManager`` is a Python class designed to\nmanage double-buffered shared memory for concurrent read/write\noperations, particularly suited for handling video frames stored \nas NumPy ndarrays.\n\nFeatures\n--------\n\n-  **Double-Buffered Memory**: Allows one buffer to be read while the\n   other is being written to, minimizing read-write conflicts.\n-  **Thread-Safe Access**: Utilizes reader-writer locks to allow\n   multiple readers and a single writer.\n-  **Dynamic Memory Management**: Dynamically creates or connects to\n   shared memory segments based on the provided base name.\n-  **Customizable Data Handling**: Supports specifying the shape and\n   data type of the NumPy ndarray.\n\nRequirements\n------------\n\n-  Python 3.x\n-  NumPy\n-  multiprocessing\n-  readerwriterlock\n-  colorlog (for enhanced logging with color)\n\nInstallation\n------------\n\nEnsure you have the required libraries:\n\n.. code:: bash\n\n   pip install numpy readerwriterlock colorlog\n\nUsage\n-----\n\nInitialization\n~~~~~~~~~~~~~~\n\nImport and initialize the manager:\n\n.. code:: python\n\n   from double_buffered_shared_memory import DoubleBufferedSharedMemoryManager\n   import numpy as np\n\n   # Initialize with default parameters\n   manager = DoubleBufferedSharedMemoryManager('image_buffer')\n\n   # Initialize with custom shape and dtype\n   manager = DoubleBufferedSharedMemoryManager('image_buffer', shape=(576, 720, 3), dtype=np.uint16)\n\nWriting to Shared Memory\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n   # Create a random HD image\n   img = np.random.randint(255, size=(1080, 1920, 3), dtype=np.uint8)\n\n   # Write to the active buffer\n   manager[0] = img\n\n0 is a convention, you can use any number, but for clarity use 0\n\nReading from Shared Memory\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n   # Switch the active buffer\n   manager.__switch()\n\n   # Read from the non-active buffer\n   img_copy = manager[0]\n\n0 is a convention, you can use any number, but for clarity use 0\n\nCleanup\n~~~~~~~\n\nIt\u2019s important to clean up shared memory resources when they\u2019re no\nlonger needed:\n\n.. code:: python\n\n   manager.cleanup()\n\nUsing with Context Manager\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe class supports context management protocol for automatic resource\nmanagement:\n\n.. code:: python\n\n   with DoubleBufferedSharedMemoryManager('image_buffer') as manager:\n       # Your code to use the manager\n       pass\n\nLogging\n-------\n\nThe class utilizes ``colorlog`` for enhanced logging. Log messages will\nvary in color based on the log level to provide a clearer and more\nintuitive understanding of the operations and events.\n\nContributing\n------------\n\nContributions, issues, and feature requests are welcome. Feel free to\ncheck `issues page <https://github.com/your-repo/issues>`__ if you want\nto contribute.\n\nAuthor\n------\n\nMassimo Ghiani m.ghiani@gmail.com\n\nLicense\n-------\n\nDistributed under the MIT License. See ``LICENSE`` for more information.\n\nAcknowledgements\n----------------\n\n-  `NumPy <https://numpy.org/>`__\n-  `readerwriterlock <https://pypi.org/project/readerwriterlock/>`__\n-  `colorlog <https://pypi.org/project/colorlog/>`__\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Package for communication with shared memory using double buffer",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/m-ghiani/DOUBLE_BUFFER_SHARED_MEMORY_MANAGER"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1d7977a3d31797ddcd6f69145b07e58fb8d0989152ffac5d3343d958a7e8f25f",
                "md5": "4aedb066da4a788993b677c66faa3158",
                "sha256": "5e64bd2a2c381af21484d0f24657303f32f3c2895b030695f915b10ee2857716"
            },
            "downloads": -1,
            "filename": "double_buffer_shared_memory_manager-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4aedb066da4a788993b677c66faa3158",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8896,
            "upload_time": "2024-01-03T04:09:43",
            "upload_time_iso_8601": "2024-01-03T04:09:43.428852Z",
            "url": "https://files.pythonhosted.org/packages/1d/79/77a3d31797ddcd6f69145b07e58fb8d0989152ffac5d3343d958a7e8f25f/double_buffer_shared_memory_manager-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "51634bcfc9a2d506b55765015a4c5bf982e4fcb1f8fe9cbaf86dc2d3bcb4d64d",
                "md5": "9b0465cbe064fe5a898658091253563b",
                "sha256": "b146cbf2cd8dc8d3f103b68a139ecb5bb59a0755052f44ac88b7b849d8b04e7f"
            },
            "downloads": -1,
            "filename": "double-buffer-shared-memory-manager-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "9b0465cbe064fe5a898658091253563b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 7640,
            "upload_time": "2024-01-03T04:09:48",
            "upload_time_iso_8601": "2024-01-03T04:09:48.652825Z",
            "url": "https://files.pythonhosted.org/packages/51/63/4bcfc9a2d506b55765015a4c5bf982e4fcb1f8fe9cbaf86dc2d3bcb4d64d/double-buffer-shared-memory-manager-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-03 04:09:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "m-ghiani",
    "github_project": "DOUBLE_BUFFER_SHARED_MEMORY_MANAGER",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "colorlog",
            "specs": [
                [
                    "==",
                    "6.8.0"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    "==",
                    "1.26.2"
                ]
            ]
        },
        {
            "name": "readerwriterlock",
            "specs": [
                [
                    "==",
                    "1.0.9"
                ]
            ]
        }
    ],
    "lcname": "double-buffer-shared-memory-manager"
}
        
Elapsed time: 0.15624s