{"action":"closed","issue":{"url":"https://api.github.com/repos/SiCKRAGETV/sickrage-issues/issues/360","labels_url":"https://api.github.com/repos/SiCKRAGETV/sickrage-issues/issues/360/labels{/name}","comments_url":"https://api.github.com/repos/SiCKRAGETV/sickrage-issues/issues/360/comments","events_url":"https://api.github.com/repos/SiCKRAGETV/sickrage-issues/issues/360/events","html_url":"https://github.com/SiCKRAGETV/sickrage-issues/issues/360","id":53815827,"number":360,"title":"processTV.py not thread safe","user":{"login":"swamp12","id":10366786,"avatar_url":"https://avatars.githubusercontent.com/u/10366786?v=3","gravatar_id":"","url":"https://api.github.com/users/swamp12","html_url":"https://github.com/swamp12","followers_url":"https://api.github.com/users/swamp12/followers","following_url":"https://api.github.com/users/swamp12/following{/other_user}","gists_url":"https://api.github.com/users/swamp12/gists{/gist_id}","starred_url":"https://api.github.com/users/swamp12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swamp12/subscriptions","organizations_url":"https://api.github.com/users/swamp12/orgs","repos_url":"https://api.github.com/users/swamp12/repos","events_url":"https://api.github.com/users/swamp12/events{/privacy}","received_events_url":"https://api.github.com/users/swamp12/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/SiCKRAGETV/sickrage-issues/labels/1%3A+Feature+request","name":"1: Feature request","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-01-08T23:34:56Z","updated_at":"2015-01-18T14:25:29Z","closed_at":"2015-01-18T14:25:29Z","body":"Concurrent web API requests to processTV.py each run in a separate thread, but because of using global variables, the results are unpredictable. The logging(returnStr) is messed up and failure conditions(process_result) are mixed up.\r\n\r\nIt is not safe to have multiple downloaders simultaneously make use the post-processing API of Sickrage. Note that the API supports both NZB's as well as Torrents.\r\n\r\nSuggested solution: don't use globals but use function parameters. \r\n\r\n    $ grep global processTV.py\r\n    global returnStr, process_result\r\n    global process_result, returnStr\r\n    global process_result, returnStr\r\n    global process_result, returnStr\r\n    global returnStr\r\n    global process_result, returnStr\r\n    global returnStr\r\n\r\nReproduction:\r\n    $ for i in `seq 1 3`; do wget -O out.$i \"http://HOSTNAME:PORT/home/postprocess/processEpisode?quiet=1&dir=%2Ftmp\"& done; echo\r\n\r\nOutput:\r\nNotice the multiple \"Successfully processed\" lines in the output. Above is a simplified example. With real simultaneous post-process requests, the results are very mixed up. Output lines of separate requests ending up in the output of unrelated other requests.\r\n\r\n    out.1:\r\n    Processing folder /tmp\r\n    TV_DOWNLOAD_DIR: ...\r\n    PostProcessing Path: /\r\n    PostProcessing Dirs: [u'tmp']\r\n    PostProcessing Files: []\r\n    PostProcessing VideoFiles: []\r\n    PostProcessing RarContent: []\r\n    PostProcessing VideoInRar: []\r\n    Processing folder tmp\r\n    Successfully processed\r\n    Successfully processed\r\n    Successfully processed\r\n\r\n    out.2:\r\n    Processing folder /tmp\r\n    TV_DOWNLOAD_DIR: ...\r\n    PostProcessing Path: /\r\n    PostProcessing Dirs: [u'tmp']\r\n    PostProcessing Files: []\r\n    PostProcessing VideoFiles: []\r\n    PostProcessing RarContent: []\r\n    PostProcessing VideoInRar: []\r\n    Processing folder tmp\r\n    Successfully processed\r\n    Successfully processed\r\n\r\n    out.3:\r\n    Processing folder /tmp\r\n    TV_DOWNLOAD_DIR: ...\r\n    PostProcessing Path: /\r\n    PostProcessing Dirs: [u'tmp']\r\n    PostProcessing Files: []\r\n    PostProcessing VideoFiles: []\r\n    PostProcessing RarContent: []\r\n    PostProcessing VideoInRar: []\r\n    Processing folder tmp\r\n    Successfully processed\r\n"}}