Exemplo n.º 1
0
class Server(object):
	"""docstring for Server"""
	def __init__(self, **kwargs):
		super(Server, self).__init__()

		self._init_attr()

	#----------------------------------------------------------------------
	# 类属性设置
	#----------------------------------------------------------------------
	def _init_attr(self):
		logger.debug('_init_attr')
		self.rd = ReadData()

	def startup(self):
		logger.debug('startup')

	def _do_command(self):
		logger.debug('do command')
		command = raw_input('>>#')
		if command == 'q':
			sys.exit(0)

	def workerDaily(self):
		logger.debug('workerDaily')
		while True:
			#logger.debug('working')
			print time.ctime()
			#self.rd.getSina();
			self.rd.writeDailyShare(self.rd.daily)
			print time.ctime()
			time.sleep(60)

	def workerShares(self):
		logger.debug('workerShares')
		while True:
			#logger.debug('working')
			print time.ctime()
			#self.rd.getSina();
			self.rd.writeDailyShare(self.rd.shares)
			print time.ctime()
			time.sleep(0.5)

	#----------------------------------------------------------------------
	# 主消息分发函数
	#----------------------------------------------------------------------
	def process(self):
		logger.debug('process')
		thr = threading.Thread(target=self.workerShares)
		thr.start()
		t_woker = threading.Thread(target=self.workerDaily)
		t_woker.start()

		if(conf.single.outofTrade()):
			sys.exit()
			logger.debug('stop')