Inter-process communication interface based on stdio piping
Project description
simple-ipc
Inter-process communication based on stdio
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
Importing
import ipc
orfrom ipc import Worker
The worker constructor
Worker(command, callback=None)
-
command
a path to an executable [arguments]
May be a list of seperate arguments that can include spaces
or of type str that is split internally with no support for spaces. -
callback
(optional) a function that is called after new data has been received
The data will be passed to the callback function, so it must have exactly one argument.
Example
def new_data(data):
print(data)
worker1 = Worker('program.exe arg1 arg2', new_data)
worker2 = Worker(['with space.exe', 'spaced arg'])
A worker object
The worker starts automatically when created.
Methods
run()
starts the workersend(data)
sends the data to the external processshutdown()
initiates the termination of all threads and clears all data
Properties
running
indicates the status of the worker (read-only)data
holds the data from the external program (read-only)
Note that any data will be converted to typestr
internally.
Example
while worker.running:
worker.send(123)
print(worker.data)
Example program
from random import randint
from ipc import Worker
def new_data(data):
print(f'Received: {data}')
worker = Worker('program.exe', new_data)
while worker.running:
number = randint(1, 10)
print(f'Sending: {number}')
worker.send(number)
print(f'Data: {worker.data}')
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
Built Distribution
Hashes for simple_ipc-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8386ec58683fee7b20617fc85cf191ee88a44caa2155398e83174b65f950a804 |
|
MD5 | 90bdb408d92da168419e64e3b7305934 |
|
BLAKE2b-256 | 95de2bf7ce4d35329cf3deef63cfa1fcbbb8b28772e80ee169f42868cee89b5d |