{"action":"opened","issue":{"url":"https://api.github.com/repos/glenfant/stopit/issues/16","repository_url":"https://api.github.com/repos/glenfant/stopit","labels_url":"https://api.github.com/repos/glenfant/stopit/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/glenfant/stopit/issues/16/comments","events_url":"https://api.github.com/repos/glenfant/stopit/issues/16/events","html_url":"https://github.com/glenfant/stopit/issues/16","id":299638348,"number":16,"title":"TimeoutException is not raised if using subprocess","user":{"login":"azastupailo","id":6131645,"avatar_url":"https://avatars1.githubusercontent.com/u/6131645?v=4","gravatar_id":"","url":"https://api.github.com/users/azastupailo","html_url":"https://github.com/azastupailo","followers_url":"https://api.github.com/users/azastupailo/followers","following_url":"https://api.github.com/users/azastupailo/following{/other_user}","gists_url":"https://api.github.com/users/azastupailo/gists{/gist_id}","starred_url":"https://api.github.com/users/azastupailo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azastupailo/subscriptions","organizations_url":"https://api.github.com/users/azastupailo/orgs","repos_url":"https://api.github.com/users/azastupailo/repos","events_url":"https://api.github.com/users/azastupailo/events{/privacy}","received_events_url":"https://api.github.com/users/azastupailo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-23T08:50:12Z","updated_at":"2018-02-23T08:50:12Z","closed_at":null,"author_association":"NONE","body":"I'm using Tesseract as OCR engine to process some documents. However, I would like to restrict the time of execution for tesseract process max to 5 mins. \r\n\r\nThe problem is that the code below sometimes kills the process properly after 5 mins, but sometimes I see a slowdown in the system due to tesseract process running for much longer.\r\nFor example, today I've noticed in logs that it took 37 minutes between `Will run OCR...` and `Tesseract timed out. Killing the ocr process ...`  (`Code block execution exceeded 300 seconds timeout` internal `stopit` log message).\r\n\r\n```python\r\ntry:\r\n    with stopit.ThreadingTimeout(300, swallow_exc=False):\r\n        logger.info('Will run OCR...')\r\n\r\n        command = 'tesseract {} {} --psm 1 -l eng hocr'.format(image_path, hocr_file_path).split()\r\n        ocr_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\r\n        # Wait for the tesseract process to finish and fetch stdout/stderr\r\n        stdout, stderr = self.ocr_process.communicate()\r\n\r\n        # ...\r\n        # Do some processing of results\r\nexcept stopit.utils.TimeoutException:\r\n    logger.exception('Tesseract timed out. Killing the ocr process ...')\r\n    ocr_process.kill()\r\n    # ...\r\n```\r\n\r\nCan you help me please to understand if I'm using `stopit` for the wrong scenario or what can be the problem?"}}
{"actor":{"display_login":"azastupailo"}}