Skip to main content

A shared memory event system for Python

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

mvent

by BRAHMAI

A Python package that provides an event-driven interface for shared memory communication between processes.

Features

  • Shared memory communication between processes
  • Event-driven architecture using decorators
  • TTL support for temporary data
  • Automatic cleanup of expired data
  • Thread-safe operations

Installation

pip install mvent

Quick Start

from mvent import MemoryEventHandler
import time

# Create a memory event handler
memory_events = MemoryEventHandler("my_pool")

# Define an event handler using decorator
@memory_events.on("user_data")
def handle_user_update(new_value):
    print(f"User data updated: {new_value}")

# Emit an event
memory_events.emit("user_data", {"name": "John", "age": 30})

# Emit with TTL (expires after 5 seconds)
memory_events.emit("user_data", {"name": "Jane"}, ttl=5.0)

# Keep the program running
time.sleep(6)
memory_events.cleanup()

How It Works

The package uses memory-mapped files for shared memory communication between processes. When a process updates a value in shared memory, all registered event handlers in other processes are automatically notified and executed.

Advanced Usage

Multiple Handlers

# Multiple handlers for the same event
@memory_events.on("user_data")
def log_user_update(new_value):
    print(f"Logging: {new_value}")

@memory_events.on("user_data")
def process_user_update(new_value):
    # Process the data
    pass

Using TTL

# Data expires after 60 seconds
memory_events.emit("temporary_data", "This will expire", ttl=60.0)

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mvent-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mvent-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file mvent-0.1.0.tar.gz.

File metadata

  • Download URL: mvent-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for mvent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 713a348c86f3ba28e0a6def4e01ee6d39b836f069c49c80a90118bdac25de2b5
MD5 25f2929a2e85592717d79c8710d91be5
BLAKE2b-256 57bf11205ed9a281d13b98ea53e19adfb21329afc6a273b6f77bf99a28e3de25

See more details on using hashes here.

File details

Details for the file mvent-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mvent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for mvent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2ed73065d9a4051a2338beecc60f0ad105fccaecf174ebb7079d73df556582e
MD5 aaff0e89760c985dd823e524cbdbc773
BLAKE2b-256 891d7e5858ecc1aa82c350ac53b7732705ede7978f8bb98b2d22b87990872854

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page