Code Monkey home page Code Monkey logo

sharedmemory's Introduction

SharedMemory

Python shared memory library based an posix-ipc.

Features

  • Shared type:
    • Basic type (int, float, bool, str)
    • list, tuple, dict and nparray
  • Management of the availability of shared memory space
  • Overloaded methods for list and dict (basic)
  • Methods to manage all defined shared space
  • Space Memory configurable
  • Semaphore

Installation

$> pip install SharedMemory

Example

Example of execution in two instances of ipython.

Client side

In [1]: from SharedMemory import SharedMemory

In [2]: # Creating client instance with a shared space named 'shared_space' with a size of 10
   ...: C = SharedMemory(name="shared_space", value="Hello", client=True)

In [4]: C.getAvailability()
Out[4]: True

In [5]: C.getValue()
Out[5]: 'Hello'

In [6]: # Waiting for Server to update shared data

In [7]: C.getValue()
Out[7]: 'World'

In [8]: C.setValue('HW')
Out[8]: True

In [9]: C.getValue()
Out[9]: 'HW'

In [10]: # Closing the client side
    ...: C.close()

In [11]: C.getAvailability()
Out[11]: False

Server side

In [1]: from SharedMemory import SharedMemory

In [2]: # Creating server instance access to the shared named 'shared_space'
   ...: S = SharedMemory(name="shared_space", client=False)

In [4]: S.getAvailability()
Out[4]: True

In [5]: S.getValue()
Out[5]: 'Hello'

In [6]: S.setValue("World")
Out[6]: True

In [7]: S.getValue()
Out[7]: 'Hello'

In [8]: # Waiting for Client to update shared data

In [9]: S.getValue()
Out[9]: 'HW'

In [10]: # Waiting Client to close the shared space

In [11]: S.getAvailability()
Out[11]: False


In [12]: # Closing the server side
    ...: S.close()
INFO: Client already stopped.

More

PyPI version Python package Upload Python Package Python License: GPL v3

sharedmemory's People

Contributors

zentetsu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sharedmemory's Issues

Dear author, hello! I tried your tool and it works very well. But I need it more in the field of deep learning. I don't know if you can add numpy-compatible functions. I would be very grateful!

Is your enhancement proposal related to a problem? Please describe.
A clear and concise description of what the problem is.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or graphics (drag-and-drop an image) about the feature request here.

Avoid crashing on successive calls of start or stop methods

Is your enhancement proposal related to a problem? Please describe.
When calling the stop or start methods for the client and the stop method for the server successively, this causes the script to crash.

Describe the solution you'd like
When these methods are called successively, the solution would be to simply inform the user that the system is already stopped or started.

Question:

The readme says:

Encapsulation of the python shared_memory library.

What is shared_memory? Is that referring to the multiprocessing moudle or something else?

Is it a port of Python3.8 SharedMemory to use with earlier versions of python?

Are there any example code you can put in the readme on how to use your SharedMemory?

[BUG] Documentation has parameter "exist" which was removed.

The sample code has this, but it is no longer valid.

,exists=False)

Expected Behavior

Sample code should be correct and accurate.

Current Behavior

TypeError: SharedMemory.__init__() got an unexpected keyword argument 'exists'

Possible Solution

Steps to Reproduce

Try to run your example.

Context (Environment)

Detailed Description

Possible Implementation

Server availability is not updated

Is your enhancement proposal related to a problem? Please describe.
When calling the getAvailability method of the client just after the server is started, the availability of the server is always set to False.

Describe the solution you'd like
When this method is called, the solution would be to simply call the _checkServerAvailability before returning the availability status.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.