{"id":21206198,"url":"https://github.com/rtmigo/bgprocess_py","last_synced_at":"2025-03-14T23:11:54.229Z","repository":{"id":57414827,"uuid":"360726050","full_name":"rtmigo/bgprocess_py","owner":"rtmigo","description":"Python package for for reading the output of processes with a time limit","archived":false,"fork":false,"pushed_at":"2021-05-12T23:38:23.000Z","size":70,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-21T15:32:13.732Z","etag":null,"topics":["output-capture","output-checking","process","python-module","timeout"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/bgprocess/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rtmigo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-23T01:16:55.000Z","updated_at":"2021-05-12T23:38:22.000Z","dependencies_parsed_at":"2022-09-10T05:11:29.527Z","dependency_job_id":null,"html_url":"https://github.com/rtmigo/bgprocess_py","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fbgprocess_py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fbgprocess_py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fbgprocess_py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Fbgprocess_py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtmigo","download_url":"https://codeload.github.com/rtmigo/bgprocess_py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243658274,"owners_count":20326467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["output-capture","output-checking","process","python-module","timeout"],"created_at":"2024-11-20T20:54:46.540Z","updated_at":"2025-03-14T23:11:54.196Z","avatar_url":"https://github.com/rtmigo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [bgprocess](https://github.com/rtmigo/bgprocess_py#bgprocess)\n\nReads the output of a process line-by-line with a time limit.\n\nTested on Linux and macOS with Python 3.7-3.9.\n\n---\n\n# Install\n\n``` bash\n$ pip3 install bgprocess\n```\n\n# Use\n\n``` python3\nfrom bgprocess import BackgroundProcess, LineWaitingTimeout\n\nwith BackgroundProcess([\"some_program\", \"arg1\", \"arg2\"]) as process:\n\n    # The process is already up and running in background.\n    # We can continue to perform operations in our program\n    \n    do_something()\n    do_something_more()\n    \n    # ok, let's check how the process is doing\n\n    try:\n        # getting for the first line from the process output.\n        # If no line was output, this call will wait for the line \n        # and only then will return the result\n        str1 = process.next_line()\n        \n        # waiting for the second line from the process output\n        str2 = process.next_line()\n        \n        # waiting for the next line, but not too long.\n        # If the line does not appear in 0.25 seconds, \n        # LineWaitingTimeout exception will be raised\n        str3 = process.next_line(read_timeout = 0.25)  # 0.25 seconds\n        \n        # skipping lines until we get the line matching the condition\n        str4 = bp.next_line(match = lambda line: line.startswith('a'))\n    \n        # skipping lines until we get the line matching the condition.\n        # If the mathing line does not appear in 3 seconds, \n        # LineWaitingTimeout exception will be raised \n        str5 = process.next_line(\n            match = lambda line: line.startswith('a'),\n            match_timeout = 3)\n            \n    except LineWaitingTimeout:\n        # we may get this exception when running next_line with \n        # read_timeout or match_timeout \n        print(\"Timeout!\")\n```\n\nIf the process is finished, `next_line` returns `None` instead of a `str`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Fbgprocess_py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtmigo%2Fbgprocess_py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Fbgprocess_py/lists"}