Ejemplo n.º 1
0
	def queueWork(self, finished, function,  *args):
		self.finished = finished
		if hasattr(function, '__call__'):
			if function.__module__ == '__main__':
				function = '.'.join([os.path.splitext(os.path.basename(sys.modules['__main__'].__file__))[0], function.__name__])
			else:
				function = '.'.join([function.__module__, function.__name__])
		self.transport.write(packByte(CONTINUE) + packUTF8(function) + packArray(packUInt, packPickle, args))
		return self.finished
Ejemplo n.º 2
0
	def dataReceived(self, data):
		self.reader.addData(data)
		status = self.reader.readByte()
		if status == CONTINUE:
			function = self.reader.readUTF8().split('.')
			package, function = '.'.join(function[:-1]), function[-1]
			module = __import__(package, globals(), locals(), ['*'], -1)
			function = getattr(module, function)
			args = self.reader.readArray(self.reader.readUInt, self.reader.readPickle)
			try:
				result = function(*args)
				if isinstance(result, Deferred):
					result = yield result
				self.transport.write(packByte(SUCCESS) + packPickle(result))
			except Exception as ex:
				self.transport.write(packByte(FAILURE) + packPickle(ex))
		elif status == KILL:
			self.transport.loseConnection()
			self.killed.callback(True)
Ejemplo n.º 3
0
	def kill(self):
		self.transport.write(packByte(KILL))