Python2.1->2.2 broke my thread/signal code?

Hugo van der Merwe s13361562 at spammenot.bach.sun.ac.za
Sun Nov 3 04:48:23 EST 2002


I have some code starting ogg123 in a new thread, I then send signals 
(SIGTERM. Clearly the code is "wrong", since it didn't survive the 2.1->2.2 
upgrade. What should I change? What am I doing wrong?

Here is the code, trimmed down significantly to only the relevant part:



#!/usr/bin/env python

import signal
import os
import time
import thread

class player:
    playerpid = 0

    def skip(self):
        os.kill(self.playerpid, signal.SIGTERM)

    def stop(self):
        os.kill(self.playerpid, signal.SIGSTOP)

    def play(self):
        pid = os.fork()
        if pid == 0:
            signal.signal(signal.SIGTERM, signal.SIG_DFL)
            os.setpgrp()  # not really sure what the effect of this is
            try:
                os.execv("/usr/bin/ogg123", 
['/usr/bin/ogg123',"/home/music/stow/owned/STEF_BOS/BESTE_VAN_BOS/07-PAPA.ogg"])
            except:
                os._exit(1)
        else: self.playerpid = pid
        os.wait()

n = player()
thread.start_new_thread(n.play,())
# Not using a thraed results in an ogg123 that can be killed with
# "kill" from bash.
#n.play()
time.sleep(5)
n.skip()   # This does the job when using 2.1, but not when using 2.2
time.sleep(5)



Thanks,
Hugo van der Merwe




More information about the Python-list mailing list