本文整理汇总了Python中signal.pthread_sigmask函数的典型用法代码示例。如果您正苦于以下问题:Python pthread_sigmask函数的具体用法?Python pthread_sigmask怎么用?Python pthread_sigmask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_sigmask函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: give_terminal_to
def give_terminal_to(pgid):
if pgid is None:
return False
oldmask = signal.pthread_sigmask(signal.SIG_BLOCK,
_block_when_giving)
try:
os.tcsetpgrp(FD_STDERR, pgid)
return True
except ProcessLookupError:
# when the process finished before giving terminal to it,
# see issue #2288
return False
except OSError as e:
if e.errno == 22: # [Errno 22] Invalid argument
# there are cases that all the processes of pgid have
# finished, then we don't need to do anything here, see
# issue #2220
return False
elif e.errno == 25: # [Errno 25] Inappropriate ioctl for device
# There are also cases where we are not connected to a
# real TTY, even though we may be run in interactive
# mode. See issue #2267 for an example with emacs
return False
else:
raise
finally:
signal.pthread_sigmask(signal.SIG_SETMASK, oldmask)
开发者ID:laerus,项目名称:xonsh,代码行数:27,代码来源:jobs.py
示例2: _run
def _run(self):
if hasattr(signal, 'pthread_sigmask'):
# this thread should not handle any signal
mask = range(1, signal.NSIG)
signal.pthread_sigmask(signal.SIG_BLOCK, mask)
self.schedule()
while self.stop_lock.acquire(0):
self.stop_lock.release()
delay = self.once()
if delay is not None:
assert delay > 0.0
with self.sleep_lock:
interrupted = self.sleep_lock.wait(timeout=delay)
if interrupted:
break
continue
task = self._task_ref()
try:
task.call()
except Exception as err:
# the task is not rescheduled on error
exc_type, exc_value, exc_tb = sys.exc_info()
# FIXME: log the traceback
print(("%s: %s" % (exc_type, exc_value)), file=sys.stderr)
break
if self.ncall is not None:
self.ncall -= 1
if self.ncall <= 0:
break
self.schedule()
开发者ID:waytai,项目名称:pytracemalloctext,代码行数:33,代码来源:tracemalloctext.py
示例3: _give_terminal_to
def _give_terminal_to(pgid):
st = _shell_tty()
if st is not None and os.isatty(st):
oldmask = signal.pthread_sigmask(signal.SIG_BLOCK,
_block_when_giving)
os.tcsetpgrp(st, pgid)
signal.pthread_sigmask(signal.SIG_SETMASK, oldmask)
开发者ID:rbignon,项目名称:xonsh,代码行数:7,代码来源:jobs.py
示例4: _serve
def _serve(self):
if hasattr(signal, "pthread_sigmask"):
signal.pthread_sigmask(signal.SIG_BLOCK, range(1, signal.NSIG))
while 1:
try:
conn = self._listener.accept()
msg = conn.recv()
if msg is None:
break
key, destination_pid = msg
send, close = self._cache.pop(key)
send(conn, destination_pid)
close()
conn.close()
except:
if not is_exiting():
import traceback
sub_warning(
"thread for sharing handles raised exception :\n"
+ "-" * 79
+ "\n"
+ traceback.format_exc()
+ "-" * 79
)
开发者ID:Naddiseo,项目名称:cpython,代码行数:25,代码来源:reduction.py
示例5: ensure_running
def ensure_running(self):
'''Make sure that semaphore tracker process is running.
This can be run from any process. Usually a child process will use
the semaphore created by its parent.'''
with self._lock:
if self._pid is not None:
# semaphore tracker was launched before, is it still running?
try:
pid, _ = os.waitpid(self._pid, os.WNOHANG)
except ChildProcessError:
# The process terminated
pass
else:
if not pid:
# => still alive
return
# => dead, launch it again
os.close(self._fd)
self._fd = None
self._pid = None
warnings.warn('semaphore_tracker: process died unexpectedly, '
'relaunching. Some semaphores might leak.')
fds_to_pass = []
try:
fds_to_pass.append(sys.stderr.fileno())
except Exception:
pass
cmd = 'from multiprocessing.semaphore_tracker import main;main(%d)'
r, w = os.pipe()
try:
fds_to_pass.append(r)
# process will out live us, so no need to wait on pid
exe = spawn.get_executable()
args = [exe] + util._args_from_interpreter_flags()
args += ['-c', cmd % r]
# bpo-33613: Register a signal mask that will block the signals.
# This signal mask will be inherited by the child that is going
# to be spawned and will protect the child from a race condition
# that can make the child die before it registers signal handlers
# for SIGINT and SIGTERM. The mask is unregistered after spawning
# the child.
try:
if _HAVE_SIGMASK:
signal.pthread_sigmask(signal.SIG_BLOCK, _IGNORED_SIGNALS)
pid = util.spawnv_passfds(exe, args, fds_to_pass)
finally:
if _HAVE_SIGMASK:
signal.pthread_sigmask(signal.SIG_UNBLOCK, _IGNORED_SIGNALS)
except:
os.close(w)
raise
else:
self._fd = w
self._pid = pid
finally:
os.close(r)
开发者ID:Eyepea,项目名称:cpython,代码行数:60,代码来源:semaphore_tracker.py
示例6: _do_exit
def _do_exit(self, signo):
if signo == 0 or signo == signal.SIGINT:
return
curses.endwin()
signal.pthread_sigmask(signal.SIG_UNBLOCK, [signo])
signal.signal(signo, signal.SIG_DFL)
os.kill(self._pid, signo)
开发者ID:anukat2015,项目名称:tbbscraper,代码行数:8,代码来源:monitor.py
示例7: _give_terminal_to
def _give_terminal_to(pgid):
# over-simplified version of:
# give_terminal_to from bash 4.3 source, jobs.c, line 4030
# this will give the terminal to the process group pgid
if _shell_tty is not None and os.isatty(_shell_tty):
oldmask = signal.pthread_sigmask(signal.SIG_BLOCK, _block_when_giving)
os.tcsetpgrp(_shell_tty, pgid)
signal.pthread_sigmask(signal.SIG_SETMASK, oldmask)
开发者ID:selepo,项目名称:xonsh,代码行数:8,代码来源:jobs.py
示例8: run
def run(self):
self.take_snapshot()
if hasattr(signal, 'pthread_sigmask'):
# Available on UNIX with Python 3.3+
signal.pthread_sigmask(signal.SIG_BLOCK, range(1, signal.NSIG))
time.sleep(init_delay)
while True:
self.take_snapshot()
time.sleep(snapshot_delay)
开发者ID:haypo,项目名称:pytracemalloc,代码行数:9,代码来源:tracemalloc_runner.py
示例9: halt
def halt(self):
oldh = signal.signal(signal.SIGINT, lambda i,f: None)
signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGINT})
for thr in self.threads:
thr.request.halt_loop()
signal.pthread_sigmask(signal.SIG_UNBLOCK, {signal.SIGINT})
signal.signal(signal.SIGINT, oldh)
开发者ID:rschoon,项目名称:scgi-pie,代码行数:9,代码来源:server.py
示例10: init_signal_handling
def init_signal_handling(self):
# In Python 3.5 system calls are no longer interrupted by signals.
# Thus, we can no longer use time.sleep() or otherwise the processing
# of signals would be delayed until the sleep has finished.
# So, we now use signal.sigtimedwait() instead. Due to the lack of
# documentation (and my unwillingness to spend more time on this than
# necessary) I'm not quite sure, if I'm doing this completely right.
# In the following, we set all signals that we're interested in as
# blocked, so that they queue up. In TimeProvider.sleep() they're taken
# again from the queue by signal.sigtimedwait().
signal.pthread_sigmask(signal.SIG_BLOCK, SIGNALS)
开发者ID:gustaebel,项目名称:pcron,代码行数:11,代码来源:scheduler.py
示例11: run
def run(host, port, Payload):
"""Select loop of scheduler.
:param host: A string with the host to bind to.
:param port: An integer with the port to bind to.
:param Payload: A class that follows the interface of ``types.Payload``.
"""
scheduler = Scheduler()
sock = init_socket('127.0.0.1', 8000)
selector = selectors.DefaultSelector()
callback = partial(handle_request, klass=Payload)
selector.register(sock, selectors.EVENT_READ, callback)
sigint_fd = linuxfd.signalfd(
signalset={signal.SIGINT, signal.SIGTERM}, nonBlocking=True
)
selector.register(sigint_fd, selectors.EVENT_READ, True)
sighup_fd = linuxfd.signalfd(signalset={signal.SIGHUP}, nonBlocking=True)
selector.register(sighup_fd, selectors.EVENT_READ, scheduler.report)
signal.pthread_sigmask(
signal.SIG_BLOCK, {signal.SIGINT, signal.SIGHUP, signal.SIGTERM}
)
timestamp = None
should_exit = False
while True:
if should_exit:
break
if timestamp is None:
timeout = timestamp
else:
timeout = timestamp - time.time()
assert timeout >= 0
logger.debug('Selecting on timeout {0}'.format(timeout))
events = selector.select(timeout)
if not events:
item = scheduler.pop()
item.execute()
timestamp = getattr(scheduler.top(), 'timestamp', None)
for key, mask in events:
callback = key.data
if not callable(callback):
should_exit = True
elif key.fileobj == sock:
item = callback(key.fileobj)
scheduler.push(item)
timestamp = scheduler.top().timestamp
else:
key.fileobj.read()
callback()
close_socket(sock)
开发者ID:mpessas,项目名称:pyscheduler,代码行数:53,代码来源:run.py
示例12: main
def main(fd):
'''Run semaphore tracker.'''
# protect the process from ^C and "killall python" etc
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_IGN)
if _HAVE_SIGMASK:
signal.pthread_sigmask(signal.SIG_UNBLOCK, _IGNORED_SIGNALS)
for f in (sys.stdin, sys.stdout):
try:
f.close()
except Exception:
pass
cache = set()
try:
# keep track of registered/unregistered semaphores
with open(fd, 'rb') as f:
for line in f:
try:
cmd, name = line.strip().split(b':')
if cmd == b'REGISTER':
cache.add(name)
elif cmd == b'UNREGISTER':
cache.remove(name)
else:
raise RuntimeError('unrecognized command %r' % cmd)
except Exception:
try:
sys.excepthook(*sys.exc_info())
except:
pass
finally:
# all processes have terminated; cleanup any remaining semaphores
if cache:
try:
warnings.warn('semaphore_tracker: There appear to be %d '
'leaked semaphores to clean up at shutdown' %
len(cache))
except Exception:
pass
for name in cache:
# For some reason the process which created and registered this
# semaphore has failed to unregister it. Presumably it has died.
# We therefore unlink it.
try:
name = name.decode('ascii')
try:
_multiprocessing.sem_unlink(name)
except Exception as e:
warnings.warn('semaphore_tracker: %r: %s' % (name, e))
finally:
pass
开发者ID:Eyepea,项目名称:cpython,代码行数:53,代码来源:semaphore_tracker.py
示例13: run
def run(self):
if hasattr(signal, 'pthread_sigmask'):
# Available on UNIX with Python 3.3+
signal.pthread_sigmask(signal.SIG_BLOCK, range(1, signal.NSIG))
while True:
if self.interval and self.snapshot_q.empty():
time.sleep(self.interval)
item = self.snapshot_q.get()
logger.info('Sending {0} snapshot file'.format(item))
logger.info('{0} items pending to send.'.format(
self.snapshot_q.qsize())
)
snapshot = tracemalloc.Snapshot.load(item)
self.client.send(snapshot)
开发者ID:kailIII,项目名称:puma,代码行数:14,代码来源:client.py
示例14: check_sigwait
def check_sigwait(self, wait_func):
signum = signal.SIGUSR1
pid = os.getpid()
old_handler = signal.signal(signum, lambda *args: None)
self.addCleanup(signal.signal, signum, old_handler)
code = '\n'.join((
'import os, time',
'pid = %s' % os.getpid(),
'signum = %s' % int(signum),
'sleep_time = %r' % self.sleep_time,
'time.sleep(sleep_time)',
'os.kill(pid, signum)',
))
old_mask = signal.pthread_sigmask(signal.SIG_BLOCK, [signum])
self.addCleanup(signal.pthread_sigmask, signal.SIG_UNBLOCK, [signum])
t0 = time.monotonic()
proc = self.subprocess(code)
with kill_on_error(proc):
wait_func(signum)
dt = time.monotonic() - t0
self.assertEqual(proc.wait(), 0)
开发者ID:Eyepea,项目名称:cpython,代码行数:26,代码来源:eintr_tester.py
示例15: _serve
def _serve(self):
if hasattr(signal, 'pthread_sigmask'):
signal.pthread_sigmask(signal.SIG_BLOCK, range(1, signal.NSIG))
while 1:
try:
with self._listener.accept() as conn:
msg = conn.recv()
if msg is None:
break
key, destination_pid = msg
send, close = self._cache.pop(key)
try:
send(conn, destination_pid)
finally:
close()
except:
if not util.is_exiting():
sys.excepthook(*sys.exc_info())
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:18,代码来源:resource_sharer.py
示例16: run
def run(self):
if hasattr(signal, 'pthread_sigmask'):
# Available on UNIX with Python 3.3+
signal.pthread_sigmask(signal.SIG_BLOCK, range(1, signal.NSIG))
while True:
logger.debug('Sleeping {0} secongs...'.format(self.interval))
time.sleep(self.interval)
filename = ("/tmp/tracemalloc-%d-%04d.dump"
% (os.getpid(), self.counter))
logger.info("Write snapshot into %s..." % filename)
gc.collect()
snapshot = tracemalloc.take_snapshot()
snapshot.dump(filename )
self.snapshot_q.put(filename)
logger.debug('Queue size: {0}'.format(self.snapshot_q.qsize()))
snapshot = None
logger.info("Snapshot written into %s" % filename)
self.counter += 1
开发者ID:kailIII,项目名称:puma,代码行数:18,代码来源:trace.py
示例17: run
def run(self):
with no_daemon_context(self.working_dir, self.lock_file, self.signals):
signal_map = {
signal.SIGHUP: self._handle_reconfigure,
signal.SIGINT: self._handle_shutdown,
signal.SIGTERM: self._handle_shutdown,
signal.SIGQUIT: self._handle_shutdown,
signal.SIGUSR1: self._handle_debug,
}
signal.pthread_sigmask(signal.SIG_BLOCK, signal_map.keys())
self._run_mcp()
self._run_www_api()
self._run_manhole()
self._run_reactor()
while True:
signum = signal.sigwait(list(signal_map.keys()))
if signum in signal_map:
logging.info(f"Got signal {str(signum)}")
signal_map[signum](signum, None)
开发者ID:Yelp,项目名称:Tron,代码行数:21,代码来源:trondaemon.py
示例18: action_toggle
def action_toggle(self, from_, chan, msg, parts):
t = time.time()
if t - self.last_toggle >= 5:
self.last_toggle = t
try:
signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGUSR1})
subprocess.call(
["/home/simark/avr/serieViaUSB/serieViaUSB", "-e", "-f", "/home/simark/avr/serieViaUSB/fichier"])
self.irc.privmsg(chan, "Your wish is my command")
# time.sleep(1)
if get_plafond_status():
self.irc.privmsg(chan, "Light is now on")
else:
self.irc.privmsg(chan, "Light is now off")
except:
raise
finally:
signal.pthread_sigmask(signal.SIG_UNBLOCK, {signal.SIGUSR1})
else:
self.irc.privmsg(
chan, "You have to wait 5 seconds between two toggles.")
开发者ID:simark,项目名称:dorsalfunbot,代码行数:21,代码来源:lightbotactions.py
示例19: test_pthread_sigmask_arguments
def test_pthread_sigmask_arguments(self):
self.assertRaises(TypeError, signal.pthread_sigmask)
self.assertRaises(TypeError, signal.pthread_sigmask, 1)
self.assertRaises(TypeError, signal.pthread_sigmask, 1, 2, 3)
self.assertRaises(OSError, signal.pthread_sigmask, 1700, [])
with self.assertRaises(ValueError):
signal.pthread_sigmask(signal.SIG_BLOCK, [signal.NSIG])
with self.assertRaises(ValueError):
signal.pthread_sigmask(signal.SIG_BLOCK, [0])
with self.assertRaises(ValueError):
signal.pthread_sigmask(signal.SIG_BLOCK, [1<<1000])
开发者ID:Eyepea,项目名称:cpython,代码行数:11,代码来源:test_signal.py
示例20: test_pthread_sigmask_valid_signals
def test_pthread_sigmask_valid_signals(self):
s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals())
self.addCleanup(signal.pthread_sigmask, signal.SIG_SETMASK, s)
# Get current blocked set
s = signal.pthread_sigmask(signal.SIG_UNBLOCK, signal.valid_signals())
self.assertLessEqual(s, signal.valid_signals())
开发者ID:Eyepea,项目名称:cpython,代码行数:6,代码来源:test_signal.py
注:本文中的signal.pthread_sigmask函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论