check for pandoc start instead of wait

This commit is contained in:
Akbar Rahman 2024-01-02 15:40:48 +00:00
parent 5c8e1e5253
commit 44bea9c982
Signed by: alvierahman90
GPG Key ID: 6217899F07CA2BDF

View File

@ -505,13 +505,33 @@ def main(args):
return 0 return 0
def start_pandoc_server():
"""
attempt to get the version of pandoc server in a loop until it is
successful and return version as string
"""
start_time = time.time()
process = subprocess.Popen(["/usr/bin/pandoc-server"],
stdout=subprocess.PIPE)
version = None
while True:
try:
resp = requests.get(f"{PANDOC_SERVER_URL}/version")
version = resp.content.decode('utf-8')
break
except requests.ConnectionError:
time.sleep(0.1)
elapsed_time = time.time() - start_time
print(f"pandoc-server started {version=} {elapsed_time=}")
return process
# TODO implement useful logging and debug printing # TODO implement useful logging and debug printing
if __name__ == '__main__': if __name__ == '__main__':
pandoc_process = subprocess.Popen(["/usr/bin/pandoc-server"], pandoc_process = start_pandoc_server()
stdout=subprocess.PIPE)
time.sleep(1)
print(pandoc_process.stdout)
try: try:
sys.exit(main(get_args())) sys.exit(main(get_args()))