Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python package for for reading the output of processes with a time limit

License

NotificationsYou must be signed in to change notification settings

rtmigo/bgprocess_py

Repository files navigation

Reads the output of a process line-by-line with a time limit.

Tested on Linux and macOS with Python 3.7-3.9.


Install

$ pip3 install bgprocess

Use

frombgprocessimportBackgroundProcess,LineWaitingTimeoutwithBackgroundProcess(["some_program","arg1","arg2"])asprocess:# The process is already up and running in background.# We can continue to perform operations in our programdo_something()do_something_more()# ok, let's check how the process is doingtry:# getting for the first line from the process output.# If no line was output, this call will wait for the line# and only then will return the resultstr1=process.next_line()# waiting for the second line from the process outputstr2=process.next_line()# waiting for the next line, but not too long.# If the line does not appear in 0.25 seconds,# LineWaitingTimeout exception will be raisedstr3=process.next_line(read_timeout=0.25)# 0.25 seconds# skipping lines until we get the line matching the conditionstr4=bp.next_line(match=lambdaline:line.startswith('a'))# skipping lines until we get the line matching the condition.# If the mathing line does not appear in 3 seconds,# LineWaitingTimeout exception will be raisedstr5=process.next_line(match=lambdaline:line.startswith('a'),match_timeout=3)exceptLineWaitingTimeout:# we may get this exception when running next_line with# read_timeout or match_timeoutprint("Timeout!")

If the process is finished,next_line returnsNone instead of astr.

About

Python package for for reading the output of processes with a time limit

Topics

Resources

License

Stars

Watchers

Forks

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp