コード例 #1
0
ファイル: main.py プロジェクト: mac22/pwsl-sbm
 def on_send_chooseFile_button_clicked(self, widget):
   '''Action invoked after choose file to send'''
   self.chooseFile_chooserdialog.hide()
   thread = MyThread(self.sending_file_action)
   self.threads.append(thread)
   thread.start()
   self.move_progress_bar_flag = True
   self.sendProgress_messagedialog.run()
   return True
コード例 #2
0
ファイル: main.py プロジェクト: mac22/pwsl-sbm
 def on_scan_button_clicked(self, widget):
   '''Action invoke after scan button click'''
   self.selected_device_to_add = None
   self.addDeviceSpinner = self.builder.get_object('scanningForDevice_addDevice_spinner')
   self.addDeviceSpinner.start()
   self.addDeviceSpinner.show()
   thread = MyThread(self.scan_for_devices_action)
   self.threads.append(thread)
   thread.start()
   self.add_dialog.run()
コード例 #3
0
ファイル: main.py プロジェクト: mac22/pwsl-sbm
 def on_yes_delete_button_clicked(self, widget):
   '''Action invoked after click on yes in remove device used for remove device'''
   device = self.get_working_device()
   if device != None:
     bm = BluetoothManager()
     thread = MyThread(bm.remove_device, device['mac'])
     self.threads.append(thread)
     thread.start()
   self.remove_dialog.hide()
   return True
コード例 #4
0
ファイル: main.py プロジェクト: mac22/pwsl-sbm
 def send_rfcomm_msg(self, widget):
   '''Action invoked after rfcomm send button click'''
   send_textview = self.builder.get_object("send_textview").get_buffer()
   data = send_textview.get_text(send_textview.get_start_iter(), send_textview.get_end_iter())
   send_textview.delete(send_textview.get_start_iter(), send_textview.get_end_iter())
   received = self.builder.get_object("received_textview").get_buffer()
   received.insert(received.get_end_iter(), "=> " + data + "\n")
   thread = MyThread(self.rfcomm_session.send_rfcomm_msg, data)
   self.threads.append(thread)
   thread.start()
コード例 #5
0
ファイル: main.py プロジェクト: mac22/pwsl-sbm
 def set_up_pin(self, widget):
   '''Action used to get pin code and pair device'''
   device = self.get_device_to_add()
   pin_entry = self.builder.get_object('pin_entry')
   pin = pin_entry.get_text()
   if device != None:
     bm = BluetoothManager()
     thread = MyThread(bm.pair_device, device['mac'], pin)
     self.threads.append(thread)
     thread.start()
   self.pin_dialog.hide()
   self.add_dialog.hide()
   return True
コード例 #6
0
ファイル: main.py プロジェクト: mac22/pwsl-sbm
 def show_rfcomm(self, widget):
   '''Action invoked after rfcomm button click'''
   bm = BluetoothManager()
   self.rfcomm_session = bm.connect_rfcomm_device(self.get_working_device()['mac'])
   if self.rfcomm_session.__class__ == BluetoothManager:
     thread = MyThread(self.receive_rfcomm_msg)
     self.threads.append(thread)
     thread.start()
     textview = self.builder.get_object("send_textview").get_buffer()
     textview.delete(textview.get_start_iter(), textview.get_end_iter())
     textview = self.builder.get_object("received_textview").get_buffer()
     textview.delete(textview.get_start_iter(), textview.get_end_iter())
     self.rfcomm_dialog.run()
   else:
     print 'kod: ' + str(self.rfcomm_session)
コード例 #7
0
ファイル: webFAQ.py プロジェクト: luweishuang/FAQ-system-1
def get_baiduzd_faq(question):
	answers = []															# 返回值
	question_list_html = None							# 返回百度知道搜索结果的第一页 html 文本
	while question_list_html is None:
		question_list_html = get_baiduzd_page(question)							# 返回百度知道搜索结果的第一页 html 文本

	if(question_list_html is None):
		print("爬取百度知道答案列表页面失败!")
		return None
	questions = get_sim_questions(question_list_html)						# questions 为 问题句子-链接 字典
	threadPool = []															# 线程队列
	for question in questions:												# 遍历每个问题链接,获取该问题的前 5 个答案
		thread = MyThread(get_a_question_ans,args=(question['link']))		# 多线程加速
		thread.start()
		threadPool.append(thread)

	for thread in threadPool:
		thread.join()

	for thread in threadPool:
		res = thread.get_result()
		if res is not None:
			answers += res

	return answers
コード例 #8
0
ファイル: main.py プロジェクト: mac22/pwsl-sbm
 def __init__(self):
   '''Initializing GTK tree objects'''
   filename = "projekt.xml"  
   self.builder = gtk.Builder()
   self.builder.add_from_file(filename)
   self.window = self.builder.get_object("main_window")
   self.add_dialog = self.builder.get_object("addDevice_dialog")
   self.pin_dialog = self.builder.get_object("pin_dialog")
   self.rfcomm_dialog = self.builder.get_object("rfcomm_dialog")
   self.remove_dialog = self.builder.get_object("removeDevice_dialog")
   self.chooseFile_chooserdialog = self.builder.get_object('chooseFile_filechooserdialog')
   self.send_progressbar = self.builder.get_object('progressbar')
   self.sendProgress_messagedialog = self.builder.get_object('sendProgress_messagedialog')
   self.prepare_search_device_tree_view()
   self.prepare_device_tree_view()
   dic = { 'on_scan_button_clicked': self.on_scan_button_clicked,
         'on_remove_button_clicked': self.on_remove_button_clicked,
         'on_send_button_clicked': self.on_send_button_clicked,
         'on_add_button_clicked' : self.on_add_button_clicked,
         'on_cancel_button_clicked' : self.on_cancel_button_clicked,
         'on_addDevice_dialog_close' : self.on_cancel_button_clicked,
         'on_no_delete_button_clicked' : self.on_no_delete_button_clicked,
         'on_yes_delete_button_clicked' : self.on_yes_delete_button_clicked,
         'on_cancel_chooseFile_button_clicked' : self.on_cancel_chooseFile_button_clicked,
         'on_send_chooseFile_button_clicked' : self.on_send_chooseFile_button_clicked,
         'on_finish_scan_action' : self.on_finish_scan_action,
         'gtk_main_quit' : self.gtk_main_quit,
         'on_newDevices_treeview_cursor_changed': self.get_selected_device,
         'on_devicesList_treeview_cursor_changed': self.get_selected_working_device,
         'on_device_add_button_clicked' : self.set_up_pin,
         'on_device_pin_cancel_button_clicked' : self.cancel_pin,
         'on_rfcomm_button_clicked' : self.show_rfcomm,
         'on_close_rfcomm_button_clicked' : self.close_rfcomm,
         'on_send_message_clicked' : self.send_rfcomm_msg
         }
   self.builder.connect_signals(dic)
   self.main_refresh(None, None)
   thread = MyThread(self.move_progress_bar)
   self.threads.append(thread)
   thread.start()
コード例 #9
0
    def get_apps_info(self, url, classification, type):
        main_html = self.get_html(url)
        if main_html == None:
            print(url + "爬取失败!")
            return
        # 获取当前分类下的总页数
        pageList_div = main_html.find("div", {"class": "pagelist", "id": "pagelist"})
        pageList = pageList_div.find_all("a")
        #当前软件分类下的总页数
        all_pages = int(pageList[len(pageList) - 2].get_text())

        # 全局变量
        global SHARE_Q
        threads = []
        # 向队列中放入任务, 真正使用时, 应该设置为可持续的放入任务
        for i in range(0, all_pages):
            current_url = url + "/" + str(i + 1)
            SHARE_Q.put(current_url)
        # 开启_WORKER_THREAD_NUM个线程
        for i in range(_WORKER_THREAD_NUM):
            thread = MyThread(self.worker(classification, type))
            # 线程开始处理任务
            thread.start()
            threads.append(thread)
        for thread in threads:
            thread.join()
        # 等待所有任务完成
        SHARE_Q.join()
コード例 #10
0
ファイル: runUI.py プロジェクト: huai-github/EvcavatorUI
 def __init__(self):
     super().__init__()
     # 注意:里面的控件对象也成为窗口对象的属性了
     self.setupUi(self)
     self.imgLine = np.zeros((h, w, 3), np.uint8)  # 画布
     self.imgBar = np.zeros((h, w, 3), np.uint8)
     self.figure = plt.figure()  # 可选参数,facecolor为背景颜色
     self.canvas = FigureCanvas(self.figure)
     self.__timer = QtCore.QTimer()  # 定时器用于定时刷新
     self.set_slot()
     self.__thread = UIFreshThread()  # 开启线程(同时将这个线程类作为一个属性)
     MyThread(self.__thread, (), name='UIFreshThread', daemon=True).start()
     self.__timer.start(1000)  # ms
     self.DeepList = []
     self.NumList = []
コード例 #11
0
ファイル: cloud_rec.py プロジェクト: SimleCat/work_qingli
def main():
    init()
    threads = [None] * num_thread
    while True:
        print ''
        time.sleep(scan_interval)
        free_th_indexs = getFreeThreads(threads)
        print "free_th_indexs:", free_th_indexs
        if not free_th_indexs:
            continue
        wait_jobs = sql_opt.query()
        print "wait_jobs: ", wait_jobs
        if not wait_jobs:
            continue
        for i in range(len(free_th_indexs)):
            if i >= len(wait_jobs):
                break
            threads[free_th_indexs[i]] = MyThread(func, wait_jobs[i])
            threads[free_th_indexs[i]].start()
コード例 #12
0
 def test_ip(self, ips):
     #检查代理ip可用性
     print("检查代理ip可用性...共有" + str(len(ips)) + "个ip待检查")
     global SHARE_Q
     threads = []
     # 向队列中放入任务, 真正使用时, 应该设置为可持续的放入任务
     for task in range(0, len(ips)):
         SHARE_Q.put(ips[task])
     # 开启_WORKER_THREAD_NUM个线程
     for i in range(_WORKER_THREAD_NUM):
         thread = MyThread(self.worker)
         thread.start()  # 线程开始处理任务
         threads.append(thread)
     for thread in threads:
         thread.join()
     # 等待所有任务完成
     SHARE_Q.join()
     print("可用代理ip:" + str(self.valid_ips))
コード例 #13
0
 def search_from_database(self, number):
     thread_list = []
     q1 = DB_Query()
     q2 = DB_Query()
     q3 = DB_Query()
     q4 = DB_Query()
     q5 = DB_Query()
     #余额查询
     t1 = MyThread(q1.balance_query, args=(number, ))
     #通信消费查询
     t2 = MyThread(q2.expenses_query, args=(number, ))
     #发展渠道
     t3 = MyThread(q3.develop_type_query, args=(number, ))
     #充值查询
     t4 = MyThread(q4.deposit_query, args=(number, ))
     #年龄查询
     t5 = MyThread(q5.age_query, args=(number, ))
     thread_list = [t1, t2, t3, t4, t5]
     for t in thread_list:
         t.start()
     for t in thread_list:
         t.join()
     balance = t1.get_result()
     fee, sms_count, flow_data, call_duration = t2.get_result()
     develop_type = t3.get_result()
     last_deposit_fee, deposit_interval_day = t4.get_result()
     age = t5.get_result()
     return [
         balance, fee, sms_count, flow_data, call_duration, develop_type,
         last_deposit_fee, age, deposit_interval_day
     ]
コード例 #14
0
def main():
    set_hook()
    thread = MyThread()
    thread.start()
    time.sleep(5)
    thread.join()
コード例 #15
0
ファイル: main.py プロジェクト: mac22/pwsl-sbm
 def main_refresh(self, widget, nothing):
   '''Main window thread with list of devices'''
   thread = MyThread(self.list_devices_action)
   self.threads.append(thread)
   thread.start()
コード例 #16
0
ファイル: server.py プロジェクト: JohnChain/mushroom
def main():
    """
    主函数

    :rtype: 0
    """
    log_msg = 'Start From Main Function'
    log_handler.work(log_msg)

    print read_config()
    print 'db_conn_info:%s' %str(db_conn_info)
    print 'arm_server: %s' %str(ARM_SERVER_ADDR)
    print 'django_server: %s' %str(DJANGO_SERVER_ADDR)
    print 'Log_files: %s' %str(log_file)
    print 'log_conf: %s' %str(log_conf)

    temp_task = TaskDeliver()
    task_deliver = MyThread(THREAD_TASK, temp_task.core, ('', ))
    task_deliver.start()

    threshold_loader = MyThread(THREAD_POLICY, load_threshold, ('', ))
    threshold_loader.start()

    temp_ram = SocketList(ArmFrameMain, arm_client_list)
    temp_ram.init(tuple(ARM_SERVER_ADDR), 10)
    ram_server = MyThread(THREAD_ARM, temp_ram.manage_list, ('', ))
    ram_server.start()

    temp_django = SocketList(DjangoFrameMain, django_client_list)
    temp_django.init(tuple(DJANGO_SERVER_ADDR), 10)
    django_server = MyThread(THREAD_DJANGO, temp_django.manage_list, ('', ))
    django_server.start()

    storage_mudule = MyThread(THREAD_SENSOR_DATA_STORAGE, sensor_data_storage, ('', ))
    storage_mudule.start()
    
    thread_dict[THREAD_TASK]    = task_deliver
    thread_dict[THREAD_ARM]     = ram_server
    thread_dict[THREAD_DJANGO]  = django_server
    thread_dict[THREAD_POLICY]  = threshold_loader
    thread_dict[THREAD_SENSOR_DATA_STORAGE] = storage_mudule
    
    signal(SIGINT, handler)
    try:
        while not main_event.isSet():
            sleep(0.01)
    except KeyboardInterrupt:
        for thread_name in thread_dict.keys():
            thread_dict[thread_name].join()
        sys.exit()
コード例 #17
0
# ch3/example1.py
import sys

sys.path.append(
    "'C:\\Users\\tnguy\\PycharmProjects\\MasteringConcurrency\\Chapter03\\my_thread.py"
)

from my_thread import MyThread

thread1 = MyThread('A', 0.5)
thread2 = MyThread('B', 0.5)

thread1.start()
thread2.start()

thread1.join()
thread2.join()

print('Finished.')
コード例 #18
0
ファイル: app.py プロジェクト: ryska/ibot
def on_tag_search():
    tag_list = pic_manager.get_tags('Urban', 10)
    user_id = api_manager.get_user_id()
    thread = MyThread("urbanshot__", "kluza1", user_id, tag_list, 0)