https://github.com/hlpdev/smem
A Python library that is used to handle interprocess communication platform independently in Python.
https://github.com/hlpdev/smem
Last synced: 5 months ago
JSON representation
A Python library that is used to handle interprocess communication platform independently in Python.
- Host: GitHub
- URL: https://github.com/hlpdev/smem
- Owner: hlpdev
- License: mit
- Created: 2024-12-06T21:29:09.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-06T22:18:25.000Z (over 1 year ago)
- Last Synced: 2025-02-04T19:46:22.826Z (about 1 year ago)
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SMem

The SMem library is used to handle **interprocess communication** ***(IPC)***
platform independently in Python.
## Usage
> [!NOTE]
> You must provide a name for the shared memory instance.
>
> The size of the shared memory defaults to 1024
>
> The create flag on the shared memory instance defaults to false,
> so make sure you ensure that an instance of the shared memory exists!
#### Creating a shared memory instance:
```python
from smem.smem import SMem
# Create the SMem instance with the "create" flag
# enabled and a specified "size" of 1024
shared_memory = SMem("my_shared_memory", create=True, size=1024)
```
#### Attaching to a shared memory instance:
Useful for reading an existing shared memory instance.
```python
from smem.smem import SMem
# Create the SMem instance with the "size" flag set to 1024
# (the same as when we created it)
shared_memory = SMem("my_shared_memory", size=1024)
```
#### Writing to shared memory
Writing to shared memory will overwrite the existing value.
```python
# Assume "shared_memory" contains an active instance of SMem
data = b"This is my data to write!"
shared_memory.write(data)
```
#### Reading shared memory
```python
# Assume "shared_memory" contains an active instance of SMem
data = shared_memory.read()
```
#### Closing an instance
Closing an instance that created the shared memory file:
```python
# Assume "shared_memory" contains an active instance of SMem
# that created the shared memory file
shared_memory.close()
shared_memory.unlink()
```
Closing an instance that did not create the shared memory file:
```python
# Assume "shared_memory" contains an active instance of SMem
# that did not create the shared memory file
shared_memory.close()
```