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


Python os.getpgrp方法代码示例

本文整理汇总了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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_ioctl.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_ioctl.py

示例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 
开发者ID:openstack,项目名称:oslo.service,代码行数:20,代码来源:service.py

示例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() 
开发者ID:ellisk42,项目名称:TikZ,代码行数:24,代码来源:timeshare.py

示例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 
开发者ID:aweimann,项目名称:traitar,代码行数:26,代码来源:traitar.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_ioctl.py

示例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 
开发者ID:ianmiell,项目名称:shutit,代码行数:17,代码来源:shutit_global.py

示例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)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:15,代码来源:util_gpid.py

示例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() 
开发者ID:FSecureLABS,项目名称:Jandroid,代码行数:9,代码来源:forwarder.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_ioctl.py

示例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) 
开发者ID:sfalkner,项目名称:pynisher,代码行数:8,代码来源:unit_tests.py

示例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) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:6,代码来源:releaseupgrader.py

示例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) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:6,代码来源:changer.py

示例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 
开发者ID:ray-project,项目名称:ray,代码行数:40,代码来源:services.py

示例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)) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:10,代码来源:test_ioctl.py


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