Skip to main content

Synchronous line-oriented IPC with command-line utilities

Project description

LineDance provides a small, dependency-free interface for conducting synchronous, line-oriented exchanges with a command-line utility. It supports Python 2.7 and Python 3.

A Partner instance owns one subprocess. Each call writes one line to its stdin and waits for stdout, stderr, or process termination:

from linedance import Partner

partner = Partner( "perl -ple '$|=1; tr/a-z/A-Z/'" )
partner( 'hello world' )
# 'HELLO WORLD'
partner.Close()

Consecutive reply lines that arrive close together are returned in one newline- joined string. Output on stderr raises PartnerError, while failure to produce the first reply before an optional timeout raises PartnerTimeout:

partner = Partner( command, timeout=10.0, interLineTimeout=0.010 )
reply = partner.Communicate( 'one request' )

The defaults are mutable attributes and may also be overridden for one call. timeout=None, the default, permits an arbitrarily long computation before the first reply. Once the first line arrives, only the resetting interLineTimeout applies, allowing any number of promptly consecutive lines to be collected.

Transcript

Every sent or received line is retained in one chronological transcript:

partner.transcript
# [(timestamp, 'stdin',  'hello again'),
#  (timestamp, 'stdout', 'HELLO AGAIN')]

The stdin, stdout, and stderr properties provide filtered views of the same history. Empty lines are preserved. A received LF and one optional preceding CR are stripped from each line.

Text and bytes

Native strings are encoded using the configurable encoding and receive the configurable terminator (default \n) unless already terminated. On Python 3, explicit bytes input is written exactly as supplied, without encoding or an added terminator.

Protocol boundaries

LineDance deliberately assumes a request/reply protocol. The child must flush its output and terminate reply lines with \n. A command that remains alive but produces no output has no observable reply boundary and therefore waits until its timeout, if any. A timeout leaves the exchange desynchronized, so the Partner refuses subsequent requests rather than risk attributing a late reply to the wrong request.

Unsolicited output is retained but is not mistaken for a reply if it arrived before the request. Protocols with prompts lacking line terminators, request IDs, or explicit completion sentinels need a protocol-specific adapter.

LineDance is public-domain software released under CC0.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linedance-0.2.0-py2.py3-none-any.whl (12.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file linedance-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: linedance-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for linedance-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4df7b2c13d2751066d45f93515c5295dc14596de8d1a2c951275f593bb8894e4
MD5 9c9c8734b736ac6f0d74fc9e9e65cb8a
BLAKE2b-256 6d214035696ccf28e295a56f27cd0a628170c61df19df03396c85bc187dad23b

See more details on using hashes here.

Supported by

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