當前位置: 首頁>>代碼示例>>Python>>正文


Python threading.main_thread方法代碼示例

本文整理匯總了Python中threading.main_thread方法的典型用法代碼示例。如果您正苦於以下問題:Python threading.main_thread方法的具體用法?Python threading.main_thread怎麽用?Python threading.main_thread使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在threading的用法示例。


在下文中一共展示了threading.main_thread方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: cron_task_host

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def cron_task_host():
    """定時任務宿主, 每分鍾檢查一次列表, 運行時間到了的定時任務"""
    while True:
        # 當全局開關關閉時, 自動退出線程
        if not enable_cron_tasks:
            if threading.current_thread() != threading.main_thread():
                exit()
            else:
                return

        sleep(60)
        try:
            task_scheduler.run()
        except:  # coverage: exclude
            errprint('ErrorDuringExecutingCronTasks')
            traceback.print_exc() 
開發者ID:aploium,項目名稱:zmirror,代碼行數:18,代碼來源:zmirror.py

示例2: ask_for_password

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def ask_for_password(username, host, message=None):
        if not SshPassCache.parent_window:
            raise Exception('SshPassCache not initialized')

        def query_psw(msg):
            password, ok = QInputDialog.getText(SshPassCache.parent_window, 'Password Dialog',
                                                msg, echo=QLineEdit.Password)
            return password, ok

        if not message:
            message = 'Enter password for ' + username + '@' + host + ':'

        if threading.current_thread() != threading.main_thread():
            password, ok = WndUtils.call_in_main_thread(query_psw, message)
        else:
            password, ok = query_psw(message)

        if not ok:
            raise CancelException
        return password 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:22,代碼來源:psw_cache.py

示例3: on_bip44_account_added

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def on_bip44_account_added(self, account: Bip44AccountType):
        """
        Called back from self.bip44_wallet after adding an item to the list of bip44 accounts. It is
        used in 'accounts view' mode for the subsequent display of read accounts.
        :param account: the account being added.
        """
        if not self.finishing:
            def fun():
                if self.utxo_src_mode == MAIN_VIEW_BIP44_ACCOUNTS:
                    self.account_list_model.add_account(account)

            log.debug('Adding account %s', account.id)
            if threading.current_thread() != threading.main_thread():
                if self.enable_synch_with_main_thread:
                    WndUtils.call_in_main_thread_ext(fun, skip_if_main_thread_locked=True)
            else:
                fun() 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:19,代碼來源:wallet_dlg.py

示例4: show_loading_tx_animation

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def show_loading_tx_animation(self):
        if not self.wdg_loading_txs_animation:
            def show():
                size = min(self.wdgSpinner.height(), self.wdgSpinner.width())
                g = self.wdgSpinner.geometry()
                g.setWidth(size)
                g.setHeight(size)
                self.wdgSpinner.setGeometry(g)
                self.wdg_loading_txs_animation = SpinnerWidget(self.wdgSpinner, size, '', 11)
                self.wdg_loading_txs_animation.show()

            if threading.current_thread() != threading.main_thread():
                if self.enable_synch_with_main_thread:
                    WndUtils.call_in_main_thread_ext(show, skip_if_main_thread_locked=True)
            else:
                show() 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:18,代碼來源:wallet_dlg.py

示例5: update_edit_controls_state

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def update_edit_controls_state(self):
        def update_fun():
            editing = (self.editing_enabled and self.cur_masternode is not None)
            self.action_gen_mn_priv_key_uncompressed.setEnabled(editing)
            self.action_gen_mn_priv_key_compressed.setEnabled(editing)
            self.btnDeleteMn.setEnabled(self.cur_masternode is not None)
            self.btnEditMn.setEnabled(not self.editing_enabled and self.cur_masternode is not None)
            self.btnCancelEditingMn.setEnabled(self.editing_enabled and self.cur_masternode is not None)
            self.btnDuplicateMn.setEnabled(self.cur_masternode is not None)
            self.action_save_config_file.setEnabled(self.app_config.is_modified())
            self.action_disconnect_hw.setEnabled(True if self.hw_client else False)
            self.btnRefreshMnStatus.setEnabled(self.cur_masternode is not None)
            self.btnRegisterDmn.setEnabled(self.cur_masternode is not None)
            self.action_sign_message_with_collateral_addr.setEnabled(self.cur_masternode is not None)
            self.action_sign_message_with_owner_key.setEnabled(self.cur_masternode is not None)
            self.action_sign_message_with_voting_key.setEnabled(self.cur_masternode is not None)
            self.update_mn_controls_state()
        if threading.current_thread() != threading.main_thread():
            self.call_in_main_thread(update_fun)
        else:
            update_fun() 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:23,代碼來源:main_dlg.py

示例6: queryDlg

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def queryDlg(message, buttons=QMessageBox.Ok | QMessageBox.Cancel, default_button=QMessageBox.Ok,
            icon=QMessageBox.Information):

        def dlg(message, buttons, default_button, icon):
            msg = QMessageBox()
            msg.setIcon(icon)
            msg.setTextInteractionFlags(
                Qt.TextSelectableByMouse | Qt.TextSelectableByKeyboard | Qt.LinksAccessibleByMouse)

            # because of the bug: https://bugreports.qt.io/browse/QTBUG-48964
            # we'll convert a message to HTML format to avoid bolded font on Mac platform
            if message.find('<html') < 0:
                message = '<html style="font-weight:normal">' + message.replace('\n', '<br>') + '</html>'

            msg.setText(message)
            msg.setStandardButtons(buttons)
            msg.setDefaultButton(default_button)
            return msg.exec_()

        if threading.current_thread() != threading.main_thread():
            return WndUtils.call_in_main_thread(dlg, message, buttons, default_button, icon)
        else:
            return dlg(message, buttons, default_button, icon) 
開發者ID:Bertrand256,項目名稱:dash-masternode-tool,代碼行數:25,代碼來源:wnd_utils.py

示例7: test_main_thread_after_fork

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def test_main_thread_after_fork(self):
        code = """if 1:
            import os, threading

            pid = os.fork()
            if pid == 0:
                main = threading.main_thread()
                print(main.name)
                print(main.ident == threading.current_thread().ident)
                print(main.ident == threading.get_ident())
            else:
                os.waitpid(pid, 0)
        """
        _, out, err = assert_python_ok("-c", code)
        data = out.decode().replace('\r', '')
        self.assertEqual(err, b"")
        self.assertEqual(data, "MainThread\nTrue\nTrue\n") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,代碼來源:test_threading.py

示例8: test_main_thread_after_fork_from_nonmain_thread

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def test_main_thread_after_fork_from_nonmain_thread(self):
        code = """if 1:
            import os, threading, sys

            def f():
                pid = os.fork()
                if pid == 0:
                    main = threading.main_thread()
                    print(main.name)
                    print(main.ident == threading.current_thread().ident)
                    print(main.ident == threading.get_ident())
                    # stdout is fully buffered because not a tty,
                    # we have to flush before exit.
                    sys.stdout.flush()
                else:
                    os.waitpid(pid, 0)

            th = threading.Thread(target=f)
            th.start()
            th.join()
        """
        _, out, err = assert_python_ok("-c", code)
        data = out.decode().replace('\r', '')
        self.assertEqual(err, b"")
        self.assertEqual(data, "Thread-1\nTrue\nTrue\n") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:27,代碼來源:test_threading.py

示例9: test_3_join_in_forked_from_thread

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def test_3_join_in_forked_from_thread(self):
        # Like the test above, but fork() was called from a worker thread
        # In the forked process, the main Thread object must be marked as stopped.

        script = """if 1:
            main_thread = threading.current_thread()
            def worker():
                childpid = os.fork()
                if childpid != 0:
                    os.waitpid(childpid, 0)
                    sys.exit(0)

                t = threading.Thread(target=joiningfunc,
                                     args=(main_thread,))
                print('end of main')
                t.start()
                t.join() # Should not block: main_thread is already stopped

            w = threading.Thread(target=worker)
            w.start()
            """
        self._run_and_join(script) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,代碼來源:test_threading.py

示例10: __init__

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def __init__(self, backend, hutcfg):
        log.debug('Starting Service Runner')
        self.backend = backend
        self.hutcfg = hutcfg
        # select the stack
        self.shim_cmd = shim_cmds.get(self.hutcfg.stack)
        if self.shim_cmd is None:
            raise RuntimeError("Unknown stack - {}".format(self.hutcfg.stack))

        # init the local runtime service
        self.runtime_server = RuntimeServer(backend)
        # init the rpc server
        self.rpc = rpc.StackHutRPC(self.backend, self.shim_cmd)

        assert threading.current_thread() == threading.main_thread()
        signal.signal(signal.SIGTERM, sigterm_handler)
        signal.signal(signal.SIGINT, sigterm_handler) 
開發者ID:nstack,項目名稱:stackhut,代碼行數:19,代碼來源:runner.py

示例11: start

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def start(self, work):
        """
        Hand the main thread to the window and continue work in the provided
        function. A state is passed as the first argument that contains a
        `running` flag. The function is expected to exit if the flag becomes
        false. The flag can also be set to false to stop the window event loop
        and continue in the main thread after the `start()` call.
        """
        assert threading.current_thread() == threading.main_thread()
        assert not self.state.running
        self.state.running = True
        self.thread = threading.Thread(target=work, args=(self.state,))
        self.thread.start()
        while self.state.running:
            try:
                before = time.time()
                self.update()
                duration = time.time() - before
                plt.pause(max(0.001, self.refresh - duration))
            except KeyboardInterrupt:
                self.state.running = False
                self.thread.join()
                return 
開發者ID:danijar,項目名稱:layered,代碼行數:25,代碼來源:plot.py

示例12: default_handle_exception_interrupt_main_thread

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def default_handle_exception_interrupt_main_thread(func):
    """
    :param func: any function. usually run in another thread.
      If some exception occurs, it will interrupt the main thread (send KeyboardInterrupt to the main thread).
      If this is run in the main thread itself, it will raise SystemExit(1).
    :return: function func wrapped
    """
    import sys
    import _thread
    import threading

    def wrapped_func(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception:
            logging.error("Exception in thread %r:" % threading.current_thread())
            sys.excepthook(*sys.exc_info())
            if threading.current_thread() is not threading.main_thread():
                _thread.interrupt_main()
            raise SystemExit(1)

    return wrapped_func 
開發者ID:rwth-i6,項目名稱:sisyphus,代碼行數:24,代碼來源:tools.py

示例13: _init_gene_sets_finished

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def _init_gene_sets_finished(self, f):
        assert self.thread() is QThread.currentThread()
        assert threading.current_thread() == threading.main_thread()
        assert self._task is not None
        assert self._task.future is f
        assert f.done()

        self._task = None
        self.progress_bar.finish()
        self.setStatusMessage('')

        try:
            results = f.result()  # type: list
            [self.data_model.appendRow(model_item) for model_item in results]
            self.filter_proxy_model.setSourceModel(self.data_model)
            self.data_view.selectionModel().selectionChanged.connect(self.commit)
            self._update_fdr()
            self.filter_data_view()
            self.set_selection()
            self.update_info_box()

        except Exception as ex:
            print(ex) 
開發者ID:biolab,項目名稱:orange3-bioinformatics,代碼行數:25,代碼來源:OWGeneSetEnrichment.py

示例14: _init_gene_sets_finished

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def _init_gene_sets_finished(self, f):
        assert self.thread() is QThread.currentThread()
        assert threading.current_thread() == threading.main_thread()
        assert self._task is not None
        assert self._task.future is f
        assert f.done()

        self._task = None
        self.progress_bar.finish()
        self.setStatusMessage('')

        try:
            results = f.result()  # type: list
            [self.data_model.appendRow(model_item) for model_item in results]
            self.filter_proxy_model.setSourceModel(self.data_model)
            self.data_view.selectionModel().selectionChanged.connect(self.commit)
            self.filter_data_view()
            self.set_selection()
            self.update_info_box()
        except Exception as ex:
            print(ex)
        self.setBlocking(False) 
開發者ID:biolab,項目名稱:orange3-bioinformatics,代碼行數:24,代碼來源:OWGeneSets.py

示例15: myChildThread

# 需要導入模塊: import threading [as 別名]
# 或者: from threading import main_thread [as 別名]
def myChildThread():
  print("Child Thread Starting")
  time.sleep(5)
  print("Current Thread ----------")
  print(threading.current_thread())
  print("-------------------------")
  print("Main Thread -------------")
  print(threading.main_thread())
  print("-------------------------")
  print("Child Thread Ending") 
開發者ID:PacktPublishing,項目名稱:Learning-Concurrency-in-Python,代碼行數:12,代碼來源:currentThread.py


注:本文中的threading.main_thread方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。