This forum has been archived. All content is frozen. Please use KDE Discuss instead.

WebControl script creates multiple instances and breaks

Tags: None
(comma "," separated)
asktoby
Registered Member
Posts
23
Karma
0
I am using Amarok 1.4.1 on KDE 3.5.2, and attempting to control Amarok using the webcontrol python script.

When I first run the webcontrol script from within Amarok all seems well. Navigating to http://localhost:4774 shows my current playlist and the pause/stop/skip buttons

However, as time goes by, more and more instances of webcontrol.py are run. (I have not been able to work out what is causing this 'python breeding'!)

When there is more than once instance of webcontrol.py the web interface loses its functionality. The playlist is still shown but there are no transport controls at the top of the screen. Here is a screenshot:
http://www.asktoby.com/miscimages/amarokWebControl.jpg

Here is some example output from ps | ax to show the multiple webcontrol.py scripts:

Code: Select all
toby@tobyjr:~$ ps ax | grep pyt
31730 ?        Sl     0:00 python /home/toby/.kde/share/apps/amarok/scripts/coverprint/coverprint.py -session 10
dee16279000114562954100000226310070_1156946833_758393
31743 ?        Sl     0:02 python /usr/share/apps/amarok/scripts/webcontrol/WebControl.py -session 10dee16279000
115470326600000056160017_1156946833_760712
31746 ?        Sl     0:00 python /usr/share/apps/amarok/scripts/webcontrol/WebControl.py -session 10dee16279000
114547136800000226310048_1156946833_761457
31750 ?        Sl     0:00 python /usr/share/apps/amarok/scripts/webcontrol/WebControl.py -session 10dee16279000
115445782300000079430016_1156946833_762146
31756 ?        Sl     0:00 python /usr/share/apps/amarok/scripts/webcontrol/WebControl.py -session 10dee16279000
115470246800000056160010_1156946833_763150
31769 ?        Sl     0:00 python /usr/share/apps/amarok/scripts/webcontrol/WebControl.py -session 10dee16279000
115471472500000059650011_1156946833_763860
31772 ?        Sl     0:00 python /usr/share/apps/amarok/scripts/webcontrol/WebControl.py -session 10dee16279000
115471771000000079020010_1156946833_764513
31775 ?        Sl     0:00 python /usr/share/apps/amarok/scripts/webcontrol/WebControl.py -session 10dee16279000
115471979700000087360010_1156946833_765167
31814 ?        Sl     0:00 python /usr/share/apps/amarok/scripts/webcontrol/WebControl.py -session 10dee16279000
115666959500000065500020_1156946833_766418
31868 ?        Sl     0:01 python /usr/share/apps/amarok/scripts/webcontrol/WebControl.py
13713 pts/5    R+     0:00 grep pyt


I would dearly love to be able to use WebControl.py to control my Amarok from a wifi PDA but at the moment I cannot do this because of the above problem.
What could be causing this 'python breeding' and what could I do to stop it?
asktoby
Registered Member
Posts
23
Karma
0
In the absence of any advice I've tried tackling this problem myself. I've done most of the work but I'm stuck with just one part. Hopefully someone with some bash scripting experience can advise?

I've written the following script:

Code: Select all
#!/bin/bash
# Script by Toby Newman. www.asktoby.com
# Suggestions welcome.
# No warranty. Use at your own risk.

# This script counts instances of the WebControl.py process
# owned by the current user only.
# ps x lists all processes owned by the current user.
# grep -v grep removes the grep process from the results
# wc -l counts the number of lines remaining in the result,
# which is also the number of WebControl.py processes found.

# here's the ps command
numOfScripts=$(ps x | grep -v grep | grep WebControl.py | wc -l)
# Echo the result
echo "$numOfScripts found"

# What to do if no WebControl is found
if [[ $numOfScripts -eq 0 ]]
then
echo "No WebControl.py found"
# Run WebControl.py. This needs testing. It may not work within
# a crontab environment due to lack of access to X server.
/usr/share/apps/amarok/scripts/webcontrol/WebControl.py -&
echo "WebControl.py started"

# Else if more than one WebControl.py is found
elif [[ $numOfScripts -gt 1 ]]
then
echo "More than one WebControl.py found"
# somehow kill all but one instance of WebControl.py?
# WORK REQUIRED
# WORK REQUIRED
# WORK REQUIRED

# Else if exactly one WebControl is found
elif [[ $numOfScripts -eq 1 ]]
then
echo "One WebControl.py found. All is well. Quitting."
fi


Basically I need some way of killing all but one of the WebControl.py scripts. I cannot think of any way to do this but I am by no means a bash scripting expert.
Can anyone advise?
asktoby
Registered Member
Posts
23
Karma
0
I am able to use awk to strip the results of ps to only show the first column of lines containing WebControl.
This gives me a list of numbers of instances to kill.
I would need to work through the list killing each one until only one remained.

ps ax |grep -v awk| awk '/WebControl/ {print $1}' 

ps ax
    lists processes running on the system
grep -v awk
    removes the line created by this line of code itself
awk /WebControl/ {print $1}'
    looks for lines containing 'WebControl' and echoes the first column, the process ID.
asktoby
Registered Member
Posts
23
Karma
0
To actually kill the WebControl instances,
$ kill PID
does not work. I guess WebControl must have been written to ignore the SIGTERM signal.
$ kill -kill PID
will kill it however.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], kde-naveen, Sogou [Bot], Yahoo [Bot]