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.1.1-py2.py3-none-any.whl (11.4 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: linedance-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.4 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.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5c24726dd1fe827538f5f9e9ef42b365b977291b22f288877a4094066dcd5078
MD5 02e8ae5d76ed05c9171fa42fca106bcc
BLAKE2b-256 7ef464bbb42b549ae47b92f7b5a513fca618e44b3b630e8fa5f2d321307404c4

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