Beispiel #1
0
	def sina_l2_hist(self,thread_num = 15, symbolList = None):
		if (symbolList is None):
			symbolList = self.symbolList
		if (self.sina is None):
			self.get_sina()
		if not(self.sina.isLogin):
			print("新浪没有登录成功,请重试")
			return False
		threads = []
		step = int( len(symbolList)/thread_num ) if ( int( len(symbolList)/thread_num )!=0 ) else 1
		symbolListSlice = [symbolList[ i : i + step] for i in range(0, len(symbolList), step)]
		for symbolList in symbolListSlice:

			loop = asyncio.get_event_loop()
			if loop.is_running():
				loop = asyncio.new_event_loop()
				asyncio.set_event_loop( loop )

			t = threading.Thread(target = self.sina.l2_hist_list, args=(symbolList,loop,) )
			threads.append(t)

		for t in threads:
			t.setDaemon(True)
			t.start()
			print("开启线程:",t.name)
		for t in threads:
			t.join()
Beispiel #2
0
    def sina_l2_hist(self, thread_num=15, symbolList=None):
        if (symbolList is None):
            symbolList = self.symbolList
        if (self.sina is None):
            self.get_sina()
        if not (self.sina.isLogin):
            print("新浪没有登录成功,请重试")
            return False
        threads = []
        step = int(
            len(symbolList) /
            thread_num) if (int(len(symbolList) / thread_num) != 0) else 1
        symbolListSlice = [
            symbolList[i:i + step] for i in range(0, len(symbolList), step)
        ]
        for symbolList in symbolListSlice:

            loop = asyncio.get_event_loop()
            if loop.is_running():
                loop = asyncio.new_event_loop()
                asyncio.set_event_loop(loop)

            t = threading.Thread(target=self.sina.l2_hist_list,
                                 args=(
                                     symbolList,
                                     loop,
                                 ))
            threads.append(t)

        for t in threads:
            t.setDaemon(True)
            t.start()
            print("开启线程:", t.name)
        for t in threads:
            t.join()
Beispiel #3
0
	def start_sina(self, callback=None):
		if (self.sina is None):
			self.get_sina()

		if not(self.sina.isLogin):
			print("新浪没有登录成功,请重试")
			return False

		threads = []
		# Cut symbolList
		step = 30
		symbolListSlice = [self.symbolList[ i : i + step] for i in range(0, len(self.symbolList), step)]
		for symbolList in symbolListSlice:

			loop = asyncio.get_event_loop()
			if loop.is_running():
				loop = asyncio.new_event_loop()
				asyncio.set_event_loop( loop )

			t = threading.Thread(target = self.sina.start_ws,args=(symbolList,loop,callback) )
			threads.append(t)
		for t in threads:
			t.setDaemon(True)
			t.start()
			print("开启线程:",t.name)
		for t in threads:
			t.join()
Beispiel #4
0
    def start_sina(self, callback=None):
        if (self.sina is None):
            self.get_sina()

        if not (self.sina.isLogin):
            print("新浪没有登录成功,请重试")
            return False

        threads = []
        # Cut symbolList
        step = 30
        symbolListSlice = [
            self.symbolList[i:i + step]
            for i in range(0, len(self.symbolList), step)
        ]
        for symbolList in symbolListSlice:

            loop = asyncio.get_event_loop()
            if loop.is_running():
                loop = asyncio.new_event_loop()
                asyncio.set_event_loop(loop)

            t = threading.Thread(target=self.sina.start_ws,
                                 args=(symbolList, loop, callback))
            threads.append(t)
        for t in threads:
            t.setDaemon(True)
            t.start()
            print("开启线程:", t.name)
        for t in threads:
            t.join()
Beispiel #5
0
def GPIO27_callback(channel):
    if not GPIO.input(27):
        global quit_program
        quit_program = True
        for t in bg_threads:
            t.join()
        GPIO.cleanup()
Beispiel #6
0
def run():
    
    threads = []
   
    func = [run_USD, run_BTC]

    print("start treading..")
    for f in func:
        t = Thread(target=f, args=())
        t.start()
        threads.append(t)
        
    
    for t in threads:
        t.join()
    def test_threading(self):

        t = threading.Thread(target=self.thread_function, args=None)

        t.start()
        t.join()
Beispiel #8
0
def fourshot(rc_control, ets = None):
    global abort_4
    
    if ets is None:
        itime = rc_control.getall()[-1]
        ets = [itime] * 4
        
    def expose(time):
        if abort_4: return
        rc_control.setexposure(time)
        
        
        print "exposing"
        while rc_control.isExposing():
            t.sleep(0.2)

        rc_control.go()
        t.sleep(5)
        
        while not rc_control.isExposureComplete():
            t.sleep(0.2)

        
    def helper():
        
        files = []
        
        cmds = GXN.Commands()
        to_move = np.array([180, 180])
        accu = -to_move[:] # accumulated move
        name = rc_control.getall()[1]
        if ets[0] != 0:
            print "move to r"
            cmds.pt(*to_move)
            accu += to_move
            t.sleep(1)
            to_move = np.array([0,0])
            rc_control.setobject("[r] %s" % name)
            files.append("[r]: %s" % rc_control.getfilename())
            expose(ets[0])
        
        to_move += np.array([-360,0])
        if ets[1] != 0:
            print "move to i"
            cmds.pt(*to_move)
            accu += to_move
            t.sleep(1)
            to_move = np.array([0,0])
            rc_control.setobject("[i] %s" % name)
            files.append("[i] %s" % rc_control.getfilename())
            expose(ets[1])
        
        to_move += np.array([0,-360])
        if ets[2] != 0:            
            print "move to g"
            cmds.pt(*to_move)
            accu += to_move
            t.sleep(1)
            to_move = np.array([0,0])
            rc_control.setobject("[g] %s" % name)
            files.append("[g] %s" % rc_control.getfilename())
            expose(ets[2])
        
        to_move += np.array([360,0])
        if ets[3] != 0:
            print "move to u"
            cmds.pt(*to_move)
            accu += to_move
            t.sleep(1)
            to_move = np.array([0,0])
            rc_control.setobject("[u] %s" % name)
            files.append("[u] %s" % rc_control.getfilename())
            expose(ets[3])
            
        rc_control.setobject("%s" % name)
        return files
    
    t= Thread(target=helper)
    t.start()
    return t.join()
Beispiel #9
0
 def mergeThreadController(self):
     if self.num_updates % MERGE_TRIGGER == 0:
         t = threading.Thread(target=self.__merge())
         t.start()
         t.join()
Beispiel #10
0
 def run(self):
     while True:
         time = Timer(120, read_req_count)
         time.start()
         time.join()