本文整理汇总了Python中os.getpgrp方法的典型用法代码示例。如果您正苦于以下问题:Python os.getpgrp方法的具体用法?Python os.getpgrp怎么用?Python os.getpgrp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.getpgrp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check_ioctl_mutate_len
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def _check_ioctl_mutate_len(self, nbytes=None):
buf = array.array('i')
intsize = buf.itemsize
ids = (os.getpgrp(), os.getsid(0))
# A fill value unlikely to be in `ids`
fill = -12345
if nbytes is not None:
# Extend the buffer so that it is exactly `nbytes` bytes long
buf.extend([fill] * (nbytes // intsize))
self.assertEqual(len(buf) * intsize, nbytes) # sanity check
else:
buf.append(fill)
with open("/dev/tty", "r") as tty:
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
rpgrp = buf[0]
self.assertEqual(r, 0)
self.assertIn(rpgrp, ids)
示例2: _check_ioctl_mutate_len
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def _check_ioctl_mutate_len(self, nbytes=None):
buf = array.array('i')
intsize = buf.itemsize
ids = (os.getpgrp(), os.getsid(0))
# A fill value unlikely to be in `ids`
fill = -12345
if nbytes is not None:
# Extend the buffer so that it is exactly `nbytes` bytes long
buf.extend([fill] * (nbytes // intsize))
self.assertEqual(len(buf) * intsize, nbytes) # sanity check
else:
buf.append(fill)
with open("/dev/tty", "rb") as tty:
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
rpgrp = buf[0]
self.assertEqual(r, 0)
self.assertIn(rpgrp, ids)
示例3: _is_daemon
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def _is_daemon():
# The process group for a foreground process will match the
# process group of the controlling terminal. If those values do
# not match, or ioctl() fails on the stdout file handle, we assume
# the process is running in the background as a daemon.
# http://www.gnu.org/software/bash/manual/bashref.html#Job-Control-Basics
try:
is_daemon = os.getpgrp() != os.tcgetpgrp(sys.stdout.fileno())
except io.UnsupportedOperation:
# Could not get the fileno for stdout, so we must be a daemon.
is_daemon = True
except OSError as err:
if err.errno == errno.ENOTTY:
# Assume we are a daemon because there is no terminal.
is_daemon = True
else:
raise
return is_daemon
示例4: execute
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def execute(self,dt):
if self.finished: return "finished"
if not self.running:
self.process = Process(target = executeInProcessGroup, args = (self,))
self.process.start()
print "timeshare child PID:",self.process.pid
os.setpgid(self.process.pid,self.process.pid)
print "timeshare process group",os.getpgid(self.process.pid)
assert os.getpgid(self.process.pid) == self.process.pid
print "my process group",os.getpgrp(),"which should be",os.getpgid(0)
assert os.getpgid(self.process.pid) != os.getpgid(0)
self.running = True
else:
os.killpg(self.process.pid, signal.SIGCONT)
self.process.join(dt)
if self.process.is_alive():
os.killpg(self.process.pid, signal.SIGSTOP)
return "still running"
else:
self.finished = True
return self.q.get()
示例5: check_dir
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def check_dir(self, out_dir):
if os.path.exists(out_dir):
#check if the process is run in background
try:
if os.getpgrp() == os.tcgetpgrp(sys.stdout.fileno()):
print self.user_message % out_dir
user_input = raw_input()
while user_input not in ["1", "2", "3"]:
user_input = raw_input().strip()
if user_input == "1":
return False
if user_input == "2":
shutil.rmtree(out_dir)
os.mkdir(out_dir)
return True
if user_input == "3":
sys.exit(1)
else:
sys.stderr.write(self.error_message % out_dir)
except OSError:
sys.stderr.write(self.error_message % out_dir)
else:
os.mkdir(out_dir)
return True
示例6: test_ioctl
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def test_ioctl(self):
# If this process has been put into the background, TIOCGPGRP returns
# the session ID instead of the process group id.
ids = (os.getpgrp(), os.getsid(0))
tty = open("/dev/tty", "r")
r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
rpgrp = struct.unpack("i", r)[0]
self.assertIn(rpgrp, ids)
示例7: determine_interactive
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def determine_interactive(self):
"""Determine whether we're in an interactive shell.
Sets interactivity off if appropriate.
cf http://stackoverflow.com/questions/24861351/how-to-detect-if-python-script-is-being-run-as-a-background-process
"""
try:
if not sys.stdout.isatty() or os.getpgrp() != os.tcgetpgrp(sys.stdout.fileno()):
self.interactive = 0
return False
except Exception:
self.interactive = 0
return False
if self.interactive == 0:
return False
return True
示例8: _save_gpid
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def _save_gpid():
plat = str(platform.system())
if plat == 'Windows':
gpid = os.getpid()
else: # unix
gpid = os.getpgrp() if USE_GPID else os.getpid()
print( 'gpid={}'.format(gpid))
with open(gpid_file, 'w') as f:
f.write(str(gpid))
print(u'wrote gpid file:{}'.format(gpid_file))
示例9: _GetPidForLock
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def _GetPidForLock():
"""Returns the PID used for host_forwarder initialization.
The PID of the "sharder" is used to handle multiprocessing. The "sharder"
is the initial process that forks that is the parent process.
"""
return os.getpgrp()
示例10: test_ioctl
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def test_ioctl(self):
# If this process has been put into the background, TIOCGPGRP returns
# the session ID instead of the process group id.
ids = (os.getpgrp(), os.getsid(0))
with open("/dev/tty", "rb") as tty:
r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
rpgrp = struct.unpack("i", r)[0]
self.assertIn(rpgrp, ids)
示例11: rogue_subprocess
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def rogue_subprocess():
pid = os.getpid()
oldgrp = os.getpgrp()
os.setpgrp()
logger.debug("{}: Changed group id from {} to {}".format(pid, oldgrp, os.getpgrp()))
time.sleep(60)
示例12: main
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def main(args):
if os.getpgrp() != os.getpid():
os.setsid()
return run_task_handler(ReleaseUpgrader, args)
示例13: main
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def main(args):
if os.getpgrp() != os.getpid():
os.setsid()
return run_task_handler(PackageChanger, args)
示例14: start_reaper
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def start_reaper(fate_share=None):
"""Start the reaper process.
This is a lightweight process that simply
waits for its parent process to die and then terminates its own
process group. This allows us to ensure that ray processes are always
terminated properly so long as that process itself isn't SIGKILLed.
Returns:
ProcessInfo for the process that was started.
"""
# Make ourselves a process group leader so that the reaper can clean
# up other ray processes without killing the process group of the
# process that started us.
try:
if sys.platform != "win32":
os.setpgrp()
except OSError as e:
errcode = e.errno
if errcode == errno.EPERM and os.getpgrp() == os.getpid():
# Nothing to do; we're already a session leader.
pass
else:
logger.warning("setpgrp failed, processes may not be "
"cleaned up properly: {}.".format(e))
# Don't start the reaper in this case as it could result in killing
# other user processes.
return None
reaper_filepath = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "ray_process_reaper.py")
command = [sys.executable, "-u", reaper_filepath]
process_info = start_ray_process(
command,
ray_constants.PROCESS_TYPE_REAPER,
pipe_stdin=True,
fate_share=fate_share)
return process_info
示例15: test_ioctl
# 需要导入模块: import os [as 别名]
# 或者: from os import getpgrp [as 别名]
def test_ioctl(self):
# If this process has been put into the background, TIOCGPGRP returns
# the session ID instead of the process group id.
ids = (os.getpgrp(), os.getsid(0))
tty = open("/dev/tty", "r")
r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ")
rpgrp = struct.unpack("i", r)[0]
self.assert_(rpgrp in ids, "%s not in %s" % (rpgrp, ids))