Cross-platform named pipe manager
Project description
namedpipe
Cross-platform named pipe manager for Python
Python only natively supports named pipes in Posix systems via os.mkfifo
. This package extends the support to Windows and defines a NPopen
class as a cross-platform solution to manage named pipes.
Installation
pip install namedpipe
Usage
import subproces as sp
from namedpipe import NPopen
# 1. Use the context-managing `NPopen` class to open an (auto-)named pipe
# - specify the mode argument with the standard notation (see built-in open())
with NPopen('r+') as pipe: # bidirectional (duplex) binary pipe
# - for an inbound pipe, specify the read access mode 'rb' or 'rt'
# - for an outbound pipe, specify the write access mode 'wb or 'wt'
# 2. Get the pipe path via pipe.path or str(pipe) to start the client program
sp.run(['my_client', pipe.path])
# auto-generated pipe paths (incremental integer pipe #):
# - Posix: $TMPDIR/pipe[a-z0-9_]{8}/[0-9]+ (random pipe directory name)
# - Windows: \\.\pipe\[0-9]+
# 3. Wait for the client to connect and create a stream
# - accepts other open() arguments: buffering, encoding, error, newline
# - blocks until connection is established
# - returns an io-compatible stream
stream = pipe.wait()
# 4. Perform read/write operation with stream (or pipe.stream) as a file-like object
b = stream.read(64)
b = pipe.stream.read(64) # alternate
in_bytes = bytearray(128)
nread = stream.readinto(in_bytes)
b_rest = stream.readall()
stream.write(out_bytes)
# 5. automatically closes the stream and destroys the pipe object
# when out of the contenxt
API Reference
TBD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
namedpipe-0.1.0.tar.gz
(15.3 kB
view hashes)
Built Distribution
namedpipe-0.1.0-py3-none-any.whl
(15.4 kB
view hashes)
Close
Hashes for namedpipe-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 660293988e20de1762e26fce4ec3f5cd71ff798882aeb3bc77e24423823cf0d0 |
|
MD5 | 612fa66d0c56fde51551398843b8f932 |
|
BLAKE2b-256 | 191b6b3a8fdb1a431c80a696f94508ba3b52c4e07e5dfb6fc53ab60a9705b654 |