Call a pp script and inmediately continue after.

Come up with a useful post-processing script? Share it here!
Post Reply
User avatar
sadnem
Newbie
Newbie
Posts: 12
Joined: November 19th, 2009, 12:16 am

Call a pp script and inmediately continue after.

Post by sadnem »

Right now I call my processing scripts through another post processing script (lets call it "caller"). I'd like to modify my "caller" script so sab post-processes downloads asynchronously, How can I do that?

"caller" is written in perl although bash solutions are also welcome.

Thank you.
Last edited by sadnem on February 11th, 2012, 10:32 am, edited 1 time in total.
User avatar
sander
Release Testers
Release Testers
Posts: 9062
Joined: January 22nd, 2008, 2:22 pm

Re: Call a pp script and inmediately continue after.

Post by sander »

Solution: the task in the script should start in the background so that the script itself can return/exit immediately.

On Linux (on Mac OS X?), starting a process in the background is easy: add a " &" at the end. Maybe a "nohup" is needed.

EDIT: On Windows it seems to work with "START ... /B"
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Call a pp script and inmediately continue after.

Post by shypike »

SABnzbd doesn't stop downloading during post-processing (unless you enabled that particular option).
The post-processing items do execute only sequentially.
User avatar
sadnem
Newbie
Newbie
Posts: 12
Joined: November 19th, 2009, 12:16 am

Re: Call a pp script and inmediately continue after.

Post by sadnem »

shypike wrote:SABnzbd doesn't stop downloading during post-processing (unless you enabled that particular option).
The post-processing items do execute only sequentially.
Yes, my mistake, main post edited.
I'd like to post-process multiple items at once, I've tried to implement sander's suggentions in my "caller" script (bash) in a way like this:

Code: Select all

nohup perl mainscript "some arguments" &
exit
But it still doesn't work, SABnzbd continues waiting for the script called in "caller" to finish.
User avatar
sander
Release Testers
Release Testers
Posts: 9062
Joined: January 22nd, 2008, 2:22 pm

Re: Call a pp script and inmediately continue after.

Post by sander »

I can confirm the behavior in SAB; only one post process process seems to be running.

So I did some test programming in python, and with "os.popen(cmd)" python waits for the script to end before continuing; a & does not help. So that could very well the reason for SAB's sequential behavior.

I did some further python programming, and with a 'os.spawnle(os.P_NOWAIT,cmd,'')' python does not wait for the process to end.

So I see two solutions:
- you change the SAB source code to use a s.spawnle(os.P_NOWAIT,cmd,'') for the post processing script
- do not change SAB, but let SAB just run a PP script to put something in a queue, and then returns immediately. You should have a separate program /daemon checking the queue and processing it.

But now my question: *why* do you want to have parallel post-processing scripts?
User avatar
sadnem
Newbie
Newbie
Posts: 12
Joined: November 19th, 2009, 12:16 am

Re: Call a pp script and inmediately continue after.

Post by sadnem »

I'm sorry for my delay answering, I couldn't reply as I was busy with a project of mine.
sander wrote:But now my question: *why* do you want to have parallel post-processing scripts?
Well because my post-processing scripts take a relatively long time but don't use a lot of computer resources, therefore, letting my computer just wait seems like a waste of time. I hate seeing my downloads queued knowing that they could have been finished if my scripts were executed asynchronously.
sander wrote:- you change the SAB source code to use a s.spawnle(os.P_NOWAIT,cmd,'') for the post processing script
as for this option (which seems like the one I'd like to go for) I've searched in /usr/share/sabnzbdplus/ for "os.popen" and would came up with these results:

Code: Select all

user@comp:/usr/share/sabnzbdplus# grep -r "popen" *
cherrypy/_cpmodpy.py:    pipein, pipeout = os.popen4("%s %s" % (cmd, args))
cherrypy/_cpmodpy.py:        os.popen("apache -k stop")
Binary file cherrypy/_cpmodpy.pyc matches
(I'm supposing the first result is the correct one)

How could I turn that os.popen4 into a os.spawnle(os.P_NOWAIT,cmd,'')?
User avatar
sander
Release Testers
Release Testers
Posts: 9062
Joined: January 22nd, 2008, 2:22 pm

Re: Call a pp script and inmediately continue after.

Post by sander »

there are also "Popen" occurences:

Code: Select all

$ grep -i popen *.py */*.py

SABHelper.py:    return subprocess.Popen('net start SABnzbd', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.read()
cherrypy/_cpmodpy.py:    pipein, pipeout = os.popen4("%s %s" % (cmd, args))
cherrypy/_cpmodpy.py:        os.popen("apache -k stop")
sabnzbd/__init__.py:    subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE,
sabnzbd/misc.py:        p = subprocess.Popen(program, shell=False, stdin=subprocess.PIPE,
sabnzbd/newsunpack.py:            os_version = subprocess.Popen("sw_vers -productVersion", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.read()
sabnzbd/newsunpack.py:        p = subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE,
sabnzbd/newsunpack.py:    p = subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE,
sabnzbd/newsunpack.py:    p = subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE,
sabnzbd/newsunpack.py:    p = subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE,
sabnzbd/newsunpack.py:        p = subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE,
sabnzbd/newsunpack.py:        # Work-around for bug in Python's Popen function,
sabnzbd/newsunpack.py:            version = subprocess.Popen(rar, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).stdout.read()
sabnzbd/newsunpack.py:            p = subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE,
sabnzbd/newsunpack.py:        p = subprocess.Popen(command, shell=need_shell, stdin=subprocess.PIPE,
sabnzbd/powersup.py:        subprocess.Popen("rundll32 powrprof.dll,SetSuspendState Hibernate")
sabnzbd/powersup.py:        subprocess.Popen("rundll32 powrprof.dll,SetSuspendState Standby")

But, strangely enough, sabnzbd/postproc.py (which sounds like the post processor) has no Popen. So you have to find out where the post processing script is started ...
Post Reply