wingo - in flumotion/trunk: . flumotion/common flumotion/worker
flumotion-commit at lists.fluendo.com
flumotion-commit at lists.fluendo.com
Mon May 7 16:25:23 CEST 2007
Author: wingo
Date: Mon May 7 16:25:19 2007
New Revision: 4876
Modified:
flumotion/trunk/ChangeLog
flumotion/trunk/flumotion/common/common.py
flumotion/trunk/flumotion/worker/job.py
flumotion/trunk/flumotion/worker/medium.py
flumotion/trunk/flumotion/worker/worker.py
Log:
2007-05-07 Andy Wingo <wingo at pobox.com>
* flumotion/worker/medium.py (WorkerMedium.remote_killJob): New
remote method, kills a job by avatarId, defaulting to SIGKILL.
Callable via flumotion-command invoke sss workerCallRemote
WORKERNAME killJob AVATARID. Fixes #499.
* flumotion/worker/worker.py (WorkerBrain.killJob): New function,
proxies to JobHeaven.killJob.
* flumotion/worker/job.py (JobHeaven.killJob): New function, kills
a job by avatarId.
(JobHeaven.kill): Use killJob.
* flumotion/common/common.py (signalPid): New function.
(termPid, killPid, checkPidRunning): Use signalPid.
Modified: flumotion/trunk/ChangeLog
==============================================================================
--- flumotion/trunk/ChangeLog (original)
+++ flumotion/trunk/ChangeLog Mon May 7 16:25:19 2007
@@ -1,5 +1,20 @@
2007-05-07 Andy Wingo <wingo at pobox.com>
+ * flumotion/worker/medium.py (WorkerMedium.remote_killJob): New
+ remote method, kills a job by avatarId, defaulting to SIGKILL.
+ Callable via flumotion-command invoke sss workerCallRemote
+ WORKERNAME killJob AVATARID. Fixes #499.
+
+ * flumotion/worker/worker.py (WorkerBrain.killJob): New function,
+ proxies to JobHeaven.killJob.
+
+ * flumotion/worker/job.py (JobHeaven.killJob): New function, kills
+ a job by avatarId.
+ (JobHeaven.kill): Use killJob.
+
+ * flumotion/common/common.py (signalPid): New function.
+ (termPid, killPid, checkPidRunning): Use signalPid.
+
* flumotion/manager/manager.py (Vishnu.__init__): Remove a FIXME
made irrelevant by [3299].
Modified: flumotion/trunk/flumotion/common/common.py
==============================================================================
--- flumotion/trunk/flumotion/common/common.py (original)
+++ flumotion/trunk/flumotion/common/common.py Mon May 7 16:25:19 2007
@@ -393,14 +393,14 @@
return int(pid)
-def termPid(pid):
+def signalPid(pid, signum):
"""
- Send the given process a TERM signal.
+ Send the given process a signal.
@returns: whether or not the process with the given pid was running
"""
try:
- os.kill(pid, signal.SIGTERM)
+ os.kill(pid, signum)
return True
except OSError, e:
if not e.errno == errno.ESRCH:
@@ -408,20 +408,21 @@
raise
return False
+def termPid(pid):
+ """
+ Send the given process a TERM signal.
+
+ @returns: whether or not the process with the given pid was running
+ """
+ return signalPid(pid, signal.SIGTERM)
+
def killPid(pid):
"""
Send the given process a KILL signal.
@returns: whether or not the process with the given pid was running
"""
- try:
- os.kill(pid, signal.SIGKILL)
- return True
- except OSError, e:
- if not e.errno == errno.ESRCH:
- # FIXME: unhandled error, maybe give some better info ?
- raise
- return False
+ return signalPid(pid, signal.SIGKILL)
def checkPidRunning(pid):
"""
@@ -429,13 +430,7 @@
@returns: whether or not a process with that pid is active.
"""
- try:
- os.kill(pid, 0)
- return True
- except OSError, e:
- if e.errno is not errno.ESRCH:
- raise
- return False
+ return signalPid(pid, 0)
def waitPidFile(type, name=None):
"""
Modified: flumotion/trunk/flumotion/worker/job.py
==============================================================================
--- flumotion/trunk/flumotion/worker/job.py (original)
+++ flumotion/trunk/flumotion/worker/job.py Mon May 7 16:25:19 2007
@@ -25,6 +25,7 @@
import os
import sys
+import signal
from twisted.cred import portal
from twisted.internet import defer, reactor
@@ -456,11 +457,18 @@
ret.addCallback(stopListening)
return ret
- def kill(self):
+ def kill(self, signum=signal.SIGKILL):
self.warning("Killing all children immediately")
- for jobInfo in self.getJobInfos():
- self.debug("Sending SIGKILL to pid %d", jobInfo.pid)
- common.killPid(jobInfo.pid)
+ for avatarId in self.getJobAvatarIds():
+ self.killJob(avatarId, signum)
+
+ def killJob(self, avatarId, signum):
+ if avatarId not in self._jobInfos:
+ raise errors.UnknownComponentError(avatarId)
+ jobInfo = self._jobInfos[avatarId]
+ self.debug("Sending signal %d to job %s at pid %d", signum,
+ avatarId, jobInfo.pid)
+ common.signalPid(jobInfo.pid, signum)
class JobAvatar(fpb.Avatar, log.Loggable):
"""
Modified: flumotion/trunk/flumotion/worker/medium.py
==============================================================================
--- flumotion/trunk/flumotion/worker/medium.py (original)
+++ flumotion/trunk/flumotion/worker/medium.py Mon May 7 16:25:19 2007
@@ -23,6 +23,8 @@
worker-side objects to handle worker clients
"""
+import signal
+
from twisted.internet import reactor
import twisted.cred.error
from twisted.internet import error
@@ -242,3 +244,21 @@
@returns: a list of componentAvatarIds
"""
return self.brain.getComponents()
+
+ def remote_killJob(self, avatarId, signum=signal.SIGKILL):
+ """Kill one of the worker's jobs.
+
+ This method is intended for exceptional purposes only; a normal
+ component shutdown is performed by the manager via calling
+ remote_stop() on the component avatar.
+
+ Raises L{flumotion.common.errors.UnknownComponentError} if the
+ job is unknown.
+
+ @param avatarId: the avatar Id of the component, e.g.
+ '/default/audio-encoder'
+ @type avatarId: string
+ @param signum: Signal to send, optional. Defaults to SIGKILL.
+ @type signum: int
+ """
+ self.brain.killJob(avatarId, signum)
Modified: flumotion/trunk/flumotion/worker/worker.py
==============================================================================
--- flumotion/trunk/flumotion/worker/worker.py (original)
+++ flumotion/trunk/flumotion/worker/worker.py Mon May 7 16:25:19 2007
@@ -281,3 +281,6 @@
def getComponents(self):
return self.jobHeaven.getJobAvatarIds()
+
+ def killJob(self, avatarId, signum):
+ self.jobHeaven.killJob(avatarId, signum)
More information about the flumotion-commit
mailing list