當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。