当前位置: 首页>>代码示例>>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;未经允许,请勿转载。