Community

Python, subprocess.run - what I should get as a result?

I run process.py using command:

try:

 result = subprocess.run("python "+filePrefix+"/PythonAbbyy/process.py "+filename+" "+filePrefix+"/out/text/header/"+name+".txt", timeout=6, shell=True)

except subprocess.TimeoutExpired:
 error = "Error"

But result returns NOTHING if process did run successfuly and I'm only display "error" when it failed.

What this process return if success and what if failure? How the correct try: except: should look like?

Regards

 

Was this article helpful?

0 out of 0 found this helpful

Comments

2 comments

  • Avatar
    Permanently deleted user

    Hi

    I was waiting for an answer for your previous question

    - https://forum.ocrsdk.com/thread/executing-in-python-stalls/

    until I saw these two new ones.

    - https://forum.ocrsdk.com/thread/python-subprocess-run-what-i-should-get-as-a-result/

    - https://forum.ocrsdk.com/thread/how-to-use-api/

     

    It should not be that hard after all with Python, please follow these steps:

    https://www.ocrsdk.com/documentation/quick-start-guide/python-ocr-sdk/

    Then tell me what output you get after step "5"


    Or have a look at another sample from ABBYY

    - https://pypi.org/project/ABBYY/

    - https://github.com/samueltc/ABBYY


    Best regards

    Koen de Leijer

     

    0
  • Avatar
    Permanently deleted user

    The problem is that output is not any structured data. So when process ended successfully you have:

    python process.py "test.png" result.txt
    Uploading..
    Id = 144bc4da-600f-4b0d-824b-95c6c55faf0a
    Status = Queued
    Waiting..
    .
    Status = Completed
    Result was written to result.txt

    But when for instance there is no connection you have:

    >python process.py "test.png" result.txt
    Uploading..
    Traceback (most recent call last):
      File "C:\Users\AppData\Local\Continuum\miniconda3\lib\site-packages\urllib3\connection.py", line 159, in _new_conn
        (self._dns_host, self.port), self.timeout, **extra_kw)
      File "C:\Users\AppData\Local\Continuum\miniconda3\lib\site-packages\urllib3\util\connection.py", line 57, in create_connection
        for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
      File "C:\Users\AppData\Local\Continuum\miniconda3\lib\socket.py", line 748, in getaddrinfo
        for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    socket.gaierror: [Errno 11001] getaddrinfo failed

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Users\AppData\Local\Continuum\miniconda3\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
        chunked=chunked)

    You have no error handling in process.py

    You do NOT return any structured data like JSON or at least XML.

    I'm not expert in Python so I ask how to manage it and know if process.py could connect to your service, how to know if completed sucessfully, how to continue next file processing even if timout...(happens often).

    Regards

    0

Please sign in to leave a comment.