Inter-process communication based on stdio
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
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 workersend(data)
sends the data to the external processstop()
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.
Source Distribution
Built Distribution
File details
Details for the file simple-ipc-1.2.1.tar.gz
.
File metadata
- Download URL: simple-ipc-1.2.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4170c8e0b3b4849da3affc7447f461c657e3de7f9bf2e184007fd1f81a486d1 |
|
MD5 | d84b64ed8d4c7cb040b434c71635371a |
|
BLAKE2b-256 | a5f52912383a76b735a44d552b661c4c2a2865cd594e46607f970bfba032e2fa |
File details
Details for the file simple_ipc-1.2.1-py2-none-any.whl
.
File metadata
- Download URL: simple_ipc-1.2.1-py2-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f81dd4799a33d5b613f1737e6d61bf0adfd6a21562aa5dbb123fff6c9c71b9eb |
|
MD5 | 54aa9eb3db299f1df0f592dda16caf07 |
|
BLAKE2b-256 | 393056d1ad8f50e101389e542af2e4a070787cc442a8d78e0d587b0883bf5b6a |