Package: b-continuous-subprocess
B.ContinuousSubprocessA helper package that lets you execute long running processes
and continuously receive their output.DescriptionImagine you want to programmatically run a command that lists objects
in a given directory. The commandsubprocess.call('ls')will do the
trick quite conveniently. However, the same approach to long running
commands likecdk deploy *orpytest -sorls / -Ris not very
convenient as you get the whole output only when the process finishes.
This package solves this inconvenience by outputting data in real-time
as the process runs.RemarksBiomapasaims to modernise life-science
industry by sharing its IT knowledge with other companies and
the community. This is an open source library intended to be used
by anyone. Improvements and pull requests are welcome.Related technologyPython 3Python subprocess PopenOS processesAssumptionsThe project assumes the following:You have basic knowledge in python programming.You have basic knowledge in OS processes.Useful sourcesRead more about python subprocess:https://docs.python.org/3/library/subprocess.html.Read more about python subprocess "Popen" specifically:https://docs.python.org/3/library/subprocess.html#popen-objectsInstallThe project is built and uploaded to PyPi. Install it by using pip.pip install b-continuous-subprocessOr directly install it through source.pip install .Usage & ExamplesThe library is extremely easy to use. Simply create an instance ofContinuousSubprocessand execute it to get a generator. Then iterate
through the generator to receive your process output in real time.fromb_continuous_subprocess.continuous_subprocessimportContinuousSubprocesscommand='cdk deploy *'generator=ContinuousSubprocess(command).execute()fordataingenerator:print(data,end='')Example how to handle errors:importjsonimportsubprocessfromb_continuous_subprocess.continuous_subprocessimportContinuousSubprocesscontinuous_process=ContinuousSubprocess('cdk deploy *')generator=continuous_process.execute()try:forlineingenerator:print(line,end='')exceptsubprocess.CalledProcessErrorasex:error_output=json.loads(ex.output)# Error message.message=error_output['message']# Stack trace.trace=error_output['trace']# The length of a stack trace (in lines).trace_size=error_output['trace_size']# The maximum possible (allowed) length of a stack trace.max_trace_size=error_output['max_trace_size']print(message)forlineintrace:print(line,end='')TestingThe project has tests that can be run.
These are mostly simple tests that can be run out-of-the-box.Run tests from a root directory withpytestpython testing library:pytestThe tests usually take less than a few seconds to complete.ContributionFound a bug? Want to add or suggest a new feature?Contributions of any kind are gladly welcome. You may contact us
directly, create a pull-request or an issue in github platform.
Lets modernize the world together.Release history0.4.0Remove unnecessary testing dependencies.Improve CI/CD pipelines.0.3.2More logging.More debugging.Fix an actual bug where the std streams que might be empty.0.3.1Cleanup process.0.3.0Add ability to control stack trace size.0.2.1Deleted all .idea files from the project.0.2.0Add stack trace when the error has happened.0.1.2Rethink the way stdout and stderr are yielded.0.1.1Pipe errors too.0.1.0Add ability to kill a process.0.0.3Start using Pylint.Start using Black.0.0.2Finalize pipelines.Finalize project structure and naming.0.0.1Initial build.