File: task.py

package info (click to toggle)
pyro 1%3A3.14-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,048 kB
  • ctags: 1,988
  • sloc: python: 11,194; xml: 128; sh: 52; makefile: 28
file content (41 lines) | stat: -rw-r--r-- 1,322 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
import Pyro.EventService.Clients
import Pyro.constants

#
# The 'main' Task abstract baseclass.
#
class PartitionableTask(object):
	def __init__(self, name):
		self.name=name
	def split(self, numPiecesHint): 
		pass  # implement in subclass
	def join(self, task):
		pass  # implement in subclass, return True to stop the whole task.
	def getResult(self):
		pass  # implement in subclass
	def __str__(self):
		return "<Task '%s'>" % self.name

#
# The subtask baseclass. The main task is split into these
# subtasks, which are distributed over the processors.
# The progress of each subtask can be monitored on the ES
# channels Distributed.cell.*  (*=subtask name)
# (use the monitor.py for this)
#
class TaskPartition(Pyro.EventService.Clients.Publisher):
	def __init__(self, name):
		Pyro.EventService.Clients.Publisher.__init__(self)
		self.name=name
	def run(self):
		self.publish("Distributed.cell."+self.name, "START")
		for pos in self.work():
			self.publish("Distributed.cell."+self.name, self.progress(pos))
		self.publish("Distributed.cell."+self.name, "FINISHED")
	def progress(self,pos):
		return 100.0*pos/100.0	# override in subclass
	def work(self):
		yield 100 	# override this generator in subclass, here the actual work is done
	def __str__(self):
		return "<TaskPartition '%s'>" % self.name