Skip to main content

A python package for cross-script communication in a simple method

Project description


Python Script Communication

This script provides functions for communication between scripts using message passing. It includes a decorator listen to mark a function as a message listener and a function send to send messages to specific channels.

Usage

Init

Function to initialise a channel (create the files). run this before using the channel!

init(channel)

  • channel: an integer representing the channel to initialise

Listen

Decorator to make a function a message listener. The function needs a parameter for the message, which it will return as a dictionary.

@listen(channel, interval=1.0)
def listener_func(message):
    # Process the received message
  • channel: An integer representing the channel to listen to.
  • interval (optional): The interval in seconds to check for new messages (default is 1.0 second).

Send

Function to send a message to a specific channel.

send(channel, message, metadata={"source": main_file_name})

  • channel: An integer representing the channel to send the message to.
  • message: A dictionary containing the message data.
  • metadata (optional): A dictionary containing additional metadata for the message. By default, it includes the source file name where the send function is called.

cleanup

Function to clean up used files. WARNING! ONLY RUN THIS WHEN YOU ARE DONE USING THE PACKAGE! it WILL halt running scripts

cleanup()

Example

Here's an example of how to use the script:

from cscomms import messaging as cscomms

cscomms.init(1)

@cscomms.listen(channel=1, interval=0.5)
def message_listener(message):
  print(message)

cscomms.send(channel=1, message={"user": "username", "message": "message"})

In this example, the script listens to channel 1 and prints any received message. It then sends a message with the key-value pair {"key": "value"} to channel 1.


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

cscomms-0.0.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

cscomms-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file cscomms-0.0.2.tar.gz.

File metadata

  • Download URL: cscomms-0.0.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for cscomms-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6c3bcc8a6e2d3e510a89369e172bd76c58ef590992d14a9596c503bdd03c67e4
MD5 91f2f5ddb54c70504c3f6a9ff55e76f0
BLAKE2b-256 cb08bf3d1a750c0e6e0791c1151ff99416a9ec9d77337b91fcea49989c1c595d

See more details on using hashes here.

File details

Details for the file cscomms-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: cscomms-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for cscomms-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 396389b541f9d1a00ff8c8c4879781189ad641e4ef0471d59d9c5e35f3e54209
MD5 f8b954e9619eaeadb7e10c321a7a9d0e
BLAKE2b-256 486a3f1b1b70197a9350cb77102565d8ad77b53fb7f59bcdd4c76427649c4642

See more details on using hashes here.

Supported by

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