Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-14-2008, 08:53 AM   #1
Registered: Apr 2005
Distribution: Ubuntu, RHEL, Darwin
Posts: 73

Rep: Reputation: 15
Python: Stdin and python apps fighting?

Here's my situation: I've written a python-based amarok script to make a libnotify popup whenever the track changes.

I've written this script because the current "standard" libnotify script is a bash script that doesn't handle things such as parentheses and slashes well, and additionally I wanted to do some more advanced imaging to the cover image.

To make a long story short, I also use WICD (which too is based on python) to connect to wireless networks.

It seems that WICD and Amarok are fighting in that whenever I reconnect to a wireless network, amarok stutters if it's playing. I have, however verified that my script is causing this--no stutter if I stop it from running. Therefore, I have concluded that it is python causing the issue.

To that end, my script uses sys.stdin.readline() (it was using raw_input()) to talk to amarok (which sends commands to scripts via stdin), if it matters, but I'm looking to solve this. I can provide the script if necessary.
Old 07-15-2008, 06:33 AM   #2
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
Originally Posted by enigma_0Z View Post
Therefore, I have concluded that it is python causing the issue.
I highly doubt it's Python rather than the actual script itself. You should probably post your script so we can see if there is any obvious problems.
Old 07-15-2008, 08:45 AM   #3
Registered: Apr 2005
Distribution: Ubuntu, RHEL, Darwin
Posts: 73

Original Poster
Rep: Reputation: 15
Script is as follows:

#!/usr/bin/env python

import sys, threading, pydcop, pynotify, Image, ImageDraw

from cgi import escape

amarok = pydcop.anyAppCalled("amarok")
pynotify.init("Amarok pynotify")

def readloop():
	while True:
		cmd = sys.stdin.readline()

		title = escape(amarok.player.title())
		artist = escape(amarok.player.artist())
		album = escape(amarok.player.album())
		cover = amarok.player.coverImage()

		coverImg =
		coverImg.thumbnail((64, 64), Image.ANTIALIAS)

		coverDraw = ImageDraw.Draw(coverImg)
		coverDraw.rectangle([(0, 0), (coverImg.size[0]-1, coverImg.size[1]-1)], outline=(0))

		cover = "/tmp/amarok-notify.png"
		cover = "file://" + cover

		if cmd == "configure":
			amarok.playlist.popupMessage("This script does not have any configuration options")

		elif cmd == "engineStateChange: playing\n":
			n = pynotify.Notification("Amarok Playing", "<b>" + title + "</b> by <b>" + artist + "</b> on <b>" + album + "</b>", cover)

		elif cmd == "engineStateChange: paused\n":
			n = pynotify.Notification("Amarok Paused", "<b>" + title + "</b> by <b>" + artist + "</b> on <b>" + album + "</b>", cover)

if __name__ == "__main__":
	t = threading.Thread(target=readloop)
After some more experimentation, it seems more likely that it was the awn icon script, not the python script, but I digress... for completeness, here's my script. I added the bit for threading on the end in an attempt to alleviate the issue. Didn't really work.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Charming Python: Python elegance and warts, Part 2 LXer Syndicated Linux News 0 08-31-2007 08:40 AM
LXer: Move to python 2.4 / Changing the packaging style for python packages LXer Syndicated Linux News 0 06-13-2006 07:54 PM
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM
Distributing Python apps with Glade UI vharishankar Programming 0 11-27-2005 03:50 AM
python (karamba/superkaramba apps) JARofHERB Programming 3 11-10-2004 10:34 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration