コード例 #1
0
ファイル: client.py プロジェクト: jonasrk/spock
	def event_loop(self):

		#Set up signal handlers
		signal.signal(signal.SIGINT, self.signal_handler)
		signal.signal(signal.SIGTERM, self.signal_handler)
		#Fire off plugins that need to run after init
		for callback in self.plugin_handlers[cflags['START_EVENT']]: callback(flag)

		#starting webinterface socket
		websock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		websock.bind(("", webinterface_port))
		websock.listen(1)
		read_list = [websock]

		while not (self.flags&cflags['KILL_EVENT'] and self.kill):
			self.getflags()
			if self.flags:
				for name, flag in cflags.items():
					if self.flags&flag:
						#Default handlers
						if flag in fhandles: fhandles[flag](self)
						#Plugin handlers
						for callback in self.plugin_handlers[flag]: callback(flag)
			for index, timer in enumerate(self.timers):
				if timer.update():
					timer.fire()
				if not timer.check():
					del self.timers[index]
			if self.daemon:
				sys.stdout.flush()
				sys.stderr.flush()
			#waiting for new commands from webinterface. 0.01s timeout
			readable, writable, errored = select.select(read_list, [], [], 0.01)
			for s in readable:
				if s is s:
					komm, addr = s.accept()
					data = komm.recv(32)
					psicraft.dispatch_psicraft_command(data.decode(), self, komm)
					komm.close()

			if self.kill_flag:
				print("closing sockets & shutting down")
				s.close()
				break
コード例 #2
0
ファイル: client.py プロジェクト: JonnyD/spock
	def event_loop(self):
		#Set up signal handlers
		signal.signal(signal.SIGINT, self.signal_handler)
		signal.signal(signal.SIGTERM, self.signal_handler)
		#Fire off plugins that need to run after init
		for callback in self.plugin_handlers[cflags['START_EVENT']]: callback(flag)

		while not (self.flags&cflags['KILL_EVENT'] and self.kill):
			self.getflags()
			if self.flags:
				for name, flag in cflags.items():
					if self.flags&flag:
						#Default handlers
						if flag in fhandles: fhandles[flag](self)
						#Plugin handlers
						for callback in self.plugin_handlers[flag]: callback(flag)
			for index, timer in enumerate(self.timers):
				if timer.update():
					timer.fire()
				if not timer.check():
					del self.timers[index]
			if self.daemon:
				sys.stdout.flush()
				sys.stderr.flush()