本文整理汇总了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
示例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
示例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
示例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
示例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()
示例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)))
示例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
示例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
示例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
示例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)
示例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
示例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
示例13: is_main_thread
# 需要导入模块: import threading [as 别名]
# 或者: from threading import _MainThread [as 别名]
def is_main_thread():
return isinstance(threading.current_thread(), threading._MainThread)
示例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()
示例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)