当前位置: 首页>>代码示例>>Python>>正文


Python threading._MainThread方法代码示例

本文整理汇总了Python中threading._MainThread方法的典型用法代码示例。如果您正苦于以下问题:Python threading._MainThread方法的具体用法?Python threading._MainThread怎么用?Python threading._MainThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在threading的用法示例。


在下文中一共展示了threading._MainThread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _set_SIGCHLD_handler

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def _set_SIGCHLD_handler():
    # Windows doesn't support SIGCHLD handler
    if sys.platform == 'win32':
        return
    # can't set signal in child threads
    if not isinstance(threading.current_thread(), threading._MainThread):
        return
    global _SIGCHLD_handler_set
    if _SIGCHLD_handler_set:
        return
    previous_handler = signal.getsignal(signal.SIGCHLD)
    if not callable(previous_handler):
        previous_handler = None

    def handler(signum, frame):
        # This following call uses `waitid` with WNOHANG from C side. Therefore,
        # Python can still get and update the process status successfully.
        _error_if_any_worker_fails()
        if previous_handler is not None:
            previous_handler(signum, frame)

    signal.signal(signal.SIGCHLD, handler)
    _SIGCHLD_handler_set = True 
开发者ID:XiaLiPKU,项目名称:EMANet,代码行数:25,代码来源:dataloader.py

示例2: call_on_qt_thread

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def call_on_qt_thread(func):
    @functools.wraps(func)
    def _call_on_qt_thread_wrapper(*args, **kwargs):
        # If the current thread is the main thread, which is the Qt thread, directly call the function.
        current_thread = threading.current_thread()
        if isinstance(current_thread, threading._MainThread):
            return func(*args, **kwargs)

        def _handle_call(ico, *args, **kwargs):
            ico.result = func(*args, **kwargs)
            ico.finish_event.set()
        inter_call_object = InterCallObject()
        new_args = tuple([inter_call_object] + list(args)[:])
        CuraApplication.getInstance().callLater(_handle_call, *new_args, **kwargs)
        inter_call_object.finish_event.wait()
        return inter_call_object.result
    return _call_on_qt_thread_wrapper 
开发者ID:Ultimaker,项目名称:Cura,代码行数:19,代码来源:Threading.py

示例3: _set_SIGCHLD_handler

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def _set_SIGCHLD_handler():
    # Windows doesn't support SIGCHLD handler
    if sys.platform == "win32":
        return
    # can't set signal in child threads
    if not isinstance(threading.current_thread(), threading._MainThread):
        return
    global _SIGCHLD_handler_set
    if _SIGCHLD_handler_set:
        return
    previous_handler = signal.getsignal(signal.SIGCHLD)
    if not callable(previous_handler):
        previous_handler = None

    def handler(signum, frame):
        # This following call uses `waitid` with WNOHANG from C side. Therefore,
        # Python can still get and update the process status successfully.
        #  C._error_if_any_worker_fails()
        if previous_handler is not None:
            previous_handler(signum, frame)

    signal.signal(signal.SIGCHLD, handler)
    _SIGCHLD_handler_set = True 
开发者ID:ethnhe,项目名称:PVN3D,代码行数:25,代码来源:persistent_dataloader.py

示例4: _set_SIGCHLD_handler

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def _set_SIGCHLD_handler():
    # Windows doesn't support SIGCHLD handler
    if sys.platform == 'win32':
        return
    # can't set signal in child threads
    if not isinstance(threading.current_thread(), threading._MainThread):
        return
    global _SIGCHLD_handler_set
    if _SIGCHLD_handler_set:
        return
    previous_handler = signal.getsignal(signal.SIGCHLD)
    if not callable(previous_handler):
        previous_handler = None

    def handler(signum, frame):
        # This following call uses `waitid` with WNOHANG from C side. Therefore,
        # Python can still get and update the process status successfully.
        #  C._error_if_any_worker_fails()
        if previous_handler is not None:
            previous_handler(signum, frame)

    signal.signal(signal.SIGCHLD, handler)
    _SIGCHLD_handler_set = True 
开发者ID:sfu-gruvi-3dv,项目名称:sanet_relocal_demo,代码行数:25,代码来源:persistent_dataloader.py

示例5: is_main_thread

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def is_main_thread():
    if six.PY2:
        return isinstance(threading.current_thread(), threading._MainThread)
    else:
        # a nicer solution with py3
        return threading.current_thread() == threading.main_thread() 
开发者ID:tensorpack,项目名称:dataflow,代码行数:8,代码来源:concurrency.py

示例6: __enter__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def __enter__(self):
            if not isinstance(threading.current_thread(), threading._MainThread):
                logging.warning("timeout only works on main thread, are you running pyspider in threads?")
                self.seconds = 0
            if self.seconds:
                signal.signal(signal.SIGALRM, self.handle_timeout)
                signal.alarm(int(math.ceil(self.seconds))) 
开发者ID:binux,项目名称:pyspider,代码行数:9,代码来源:utils.py

示例7: is_main_thread

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def is_main_thread():
    """returns true if we are within the main thread"""
    cur_thread = threading.current_thread()
    if sys.version_info >= (3, 4):
        return cur_thread is threading.main_thread()
    else:
        # noinspection PyUnresolvedReferences
        return isinstance(cur_thread, threading._MainThread)


# noinspection PyPep8Naming 
开发者ID:tox-dev,项目名称:tox,代码行数:13,代码来源:stdlib.py

示例8: inside_main_thread

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def inside_main_thread():
        in_main_thread = isinstance(threading.current_thread(), threading._MainThread)
        return in_main_thread 
开发者ID:nokia,项目名称:moler,代码行数:5,代码来源:connection_observer.py

示例9: check

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def check():
        """
            The actual checker.
        """

        try:  # for Python > 3.4
            res = threading.current_thread() is threading.main_thread()
        except AttributeError:
            res = isinstance(threading.current_thread(), threading._MainThread)

        return res 
开发者ID:pysathq,项目名称:pysat,代码行数:13,代码来源:_utils.py

示例10: effective_n_jobs

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def effective_n_jobs(self, n_jobs):
        """Determine the number of jobs which are going to run in parallel.

        This also checks if we are attempting to create a nested parallel
        loop.
        """
        if mp is None:
            return 1

        if mp.current_process().daemon:
            # Daemonic processes cannot have children
            if n_jobs != 1:
                warnings.warn(
                    'Multiprocessing-backed parallel loops cannot be nested,'
                    ' setting n_jobs=1',
                    stacklevel=3)
            return 1

        if not isinstance(threading.current_thread(), threading._MainThread):
            # Prevent posix fork inside in non-main posix threads
            warnings.warn(
                'Multiprocessing-backed parallel loops cannot be nested'
                ' below threads, setting n_jobs=1',
                stacklevel=3)
            return 1

        return super(MultiprocessingBackend, self).effective_n_jobs(n_jobs) 
开发者ID:flennerhag,项目名称:mlens,代码行数:29,代码来源:_parallel_backends.py

示例11: test_is_main_thread

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def test_is_main_thread():
    from _pydevd_bundle.pydevd_utils import is_current_thread_main_thread
    from _pydevd_bundle.pydevd_utils import dump_threads
    if not is_current_thread_main_thread():
        error_msg = 'Current thread does not seem to be a main thread. Details:\n'
        current_thread = threading.current_thread()
        error_msg += 'Current thread: %s\n' % (current_thread,)

        if hasattr(threading, 'main_thread'):
            error_msg += 'Main thread found: %s\n' % (threading.main_thread(),)
        else:
            error_msg += 'Current main thread not instance of: %s (%s)' % (
                threading._MainThread, current_thread.__class__.__mro__,)

        try:
            from StringIO import StringIO
        except:
            from io import StringIO

        stream = StringIO()
        dump_threads(stream=stream)
        error_msg += '\n\n' + stream.getvalue()
        raise AssertionError(error_msg)

    class NonMainThread(threading.Thread):

        def run(self):
            self.is_main_thread = is_current_thread_main_thread()

    non_main_thread = NonMainThread()
    non_main_thread.start()
    non_main_thread.join()
    assert not non_main_thread.is_main_thread 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:35,代码来源:test_utilities.py

示例12: _in_main_thread

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def _in_main_thread():
        # noinspection PyUnresolvedReferences
        return isinstance(threading.current_thread(), threading._MainThread)


    #
    # Class preparation with external monkey patching 
开发者ID:CERT-Polska,项目名称:n6,代码行数:9,代码来源:timeout_callback_manager.py

示例13: is_main_thread

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def is_main_thread():
    return isinstance(threading.current_thread(), threading._MainThread) 
开发者ID:crytic,项目名称:etheno,代码行数:4,代码来源:threadwrapper.py

示例14: start_gtk

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def start_gtk():
    # check if twisted is imported
    if reactor_required():
        from twisted.internet import reactor
        import threading
        is_main_thread = isinstance(threading.current_thread(), threading._MainThread)
        reactor.run(installSignalHandlers=is_main_thread)
    else:
        Gtk.main() 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:11,代码来源:start.py

示例15: _init_watcher

# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def _init_watcher(self):
        with events._lock:
            if self._watcher is None:  # pragma: no branch
                self._watcher = SafeChildWatcher()
                if isinstance(threading.current_thread(),
                              threading._MainThread):
                    self._watcher.attach_loop(self._local._loop) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:unix_events.py


注:本文中的threading._MainThread方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。