Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Inter-process communication based on stdio

Project description

simple-ipc

Inter-process communication based on stdio

Python Version PyPI Version License

A simple python interface for inter-process communication, a way to asynchronously exchange data with external programs at runtime. The internal mechanism functions by writing data to stdout and reading from stdin using multi threading.

Installation

pip install simple-ipc

Usage

Import the module first:

  • import ipc
  • from ipc import Worker

Parameters

Worker(command, callback=None, start=True, verbose=False)
  • command a path to an executable along with optional arguments

    • list: may include spaces
    • str: no support for spaces
  • callback (optional) a function that is called after new data has been received

    • must take exactly one argument
  • start (optional) start the worker automatically when created

  • verbose (optional) print status messages

Examples

worker = Worker(['with space.exe', 'spaced arg'], start=False)
with Worker('program.exe', verbose=True) as worker:
    ...
Worker('path/to/program.exe arg', lambda data: print(data))

A worker object

All data will be converted to type str internally.

Methods

  • start() starts the worker
  • send(data) sends the data to the external process
  • stop() initiates the termination of all threads and clears all data

Properties

  • running indicates the status of the worker (read-only)
  • data contains the most recent value (read-only)

Example program

from random import randint
from ipc import Worker

def process(data):
    if int(data) == 5:
        print('Process data...')

worker = Worker('program.exe', process)

while worker.running:
    number = randint(1, 10)
    worker.send(number)
    print(f'Data: {worker.data}')

More example code can be found here.

Project details


Download files

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

Files for simple-ipc, version 1.2.1
Filename, size File type Python version Upload date Hashes
Filename, size simple_ipc-1.2.1-py2-none-any.whl (4.5 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size simple-ipc-1.2.1.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page