Sonarr: Let Custom Post Processing Scripts Run in Background

Created on 13 Sep 2017  路  6Comments  路  Source: Sonarr/Sonarr

Currently, ProcessProvider.StartAndCapture() is used for the calling of a custom post processing script. This leads to Sonarr waiting with further processing until the script has finished. Some post processing tasks cloud be perfectly executed in the background while Sonarr processes further files like normal, eliminating unnecessary waiting times, especially for time-consuming custom post processing scripts.

A Toggle in the settings screen for custom scripts could solve this. The default value would still wait for the script to finish like previously, but when toggled, Sonarr would just spawn the process and resume business as usual.


I actually tried evading the capturing by Sonarr, my script is in Python and I tried os.fork(), subprocess.Popen(), os.setsid(), the Process library and more, but to no avail. If there is anyone who knows how to beat the WaitForExit() function used in StartAndCapture(), I would be grateful for pointers.

1% connection enhancement up-for-grabs

Most helpful comment

Following up on this, I figured out the issue. WaitForExit seems to hang on open stdout/stderr. I used this script to make my script async:

#!/bin/bash

~/foo.py "$@" >&- 2>&- &

Hope this helps the next person to come along.

All 6 comments

I think this could lead to some complications if it was enabled without awareness, but I'm not opposed to it.

You can easily just start a different script and let the current script finish, how depends on which kind of script. I see no reason why Sonarr should be taking care of that.

@Taloth should we close this then? The only downside would be not capturing the output, but that's probably going to be pretty ugly when running async.

Yup, leave it up to the callee to deal with it.

Sorry to bring an old issue up, but I don't see how

You can easily just start a different script and let the current script finish
works.

As the original poster noted the mono Process.WaitForExit() seems just about impossible to defeat. I've tried writing bash scripts with & disown nohup setsid and combination of all of the above. WaitForExit is not fooled.

see https://stackoverflow.com/questions/20929747/fooling-system-diagnostics-process-waitforexit for similar problems

Following up on this, I figured out the issue. WaitForExit seems to hang on open stdout/stderr. I used this script to make my script async:

#!/bin/bash

~/foo.py "$@" >&- 2>&- &

Hope this helps the next person to come along.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mommalongnips picture mommalongnips  路  3Comments

mabasic picture mabasic  路  3Comments

markus101 picture markus101  路  4Comments

skube picture skube  路  4Comments

Taloth picture Taloth  路  4Comments