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


Python os.setpgrp方法代码示例

本文整理汇总了Python中os.setpgrp方法的典型用法代码示例。如果您正苦于以下问题:Python os.setpgrp方法的具体用法?Python os.setpgrp怎么用?Python os.setpgrp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.setpgrp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _popen_kwargs

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def _popen_kwargs(prevent_sigint=False):
    startupinfo = None
    preexec_fn = None
    creationflags = 0
    if sys.platform.startswith("win"):
        # Stops executable from flashing on Windows (see #22)
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    if prevent_sigint:
        # Prevent propagation of sigint (see #4)
        # https://stackoverflow.com/questions/5045771
        if sys.platform.startswith("win"):
            creationflags = 0x00000200
        else:
            preexec_fn = os.setpgrp  # the _pre_exec does not seem to work
    return {
        "startupinfo": startupinfo,
        "creationflags": creationflags,
        "preexec_fn": preexec_fn,
    } 
开发者ID:imageio,项目名称:imageio-ffmpeg,代码行数:22,代码来源:_utils.py

示例2: create_executable_limits

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def create_executable_limits(self) -> Optional[Callable[[], None]]:
        try:
            import resource
            from dmoj.utils.os_ext import oom_score_adj, OOM_SCORE_ADJ_MAX

            def limit_executable():
                os.setpgrp()

                # Mark compiler process as first to die in an OOM situation, just to ensure that the judge will not
                # be killed.
                try:
                    oom_score_adj(OOM_SCORE_ADJ_MAX)
                except Exception:
                    import traceback

                    traceback.print_exc()

                resource.setrlimit(resource.RLIMIT_FSIZE, (self.executable_size, self.executable_size))

            return limit_executable
        except ImportError:
            return None 
开发者ID:DMOJ,项目名称:judge-server,代码行数:24,代码来源:compiled_executor.py

示例3: open

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def open(self):
        if self.platform == 'Windows':
            DETACHED_PROCESS = 0x00000008
            b3d_exe = os.path.join(
                self.root_folder, self.version, "blender.exe")
            process = subprocess.Popen(b3d_exe, shell=True, stdin=None, stdout=None,
                                       stderr=None, close_fds=True, creationflags=DETACHED_PROCESS)
        elif self.platform == 'Linux':
            b3d_exe = os.path.join(self.root_folder, self.version, "blender")
            process = subprocess.Popen(
                'nohup "' + b3d_exe + '"', shell=True, stdout=None, stderr=None, close_fds=True, preexec_fn=os.setpgrp)

        self.processes.append(process)

        if (len(self.processes) == 1):
            self.observe_instances = ObserveInstances(self)
            self.observe_instances.started.connect(self.observe_started)
            self.observe_instances.finished.connect(self.observe_finished)
            self.observe_instances.count_changed.connect(self.count_changed)
            self.observe_instances.start()
        else:
            self.count_changed() 
开发者ID:DotBow,项目名称:Blender-Version-Manager,代码行数:24,代码来源:version_layout.py

示例4: _popen_kwargs

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def _popen_kwargs(prevent_sigint=False):
    startupinfo = None
    preexec_fn = None
    creationflags = 0
    if sys.platform.startswith("win"):
        # Stops executable from flashing on Windows (see imageio/imageio-ffmpeg#22)
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    if prevent_sigint:
        # Prevent propagation of sigint (see imageio/imageio-ffmpeg#4)
        # https://stackoverflow.com/questions/5045771
        if sys.platform.startswith("win"):
            creationflags = 0x00000200
        else:
            preexec_fn = os.setpgrp  # the _pre_exec does not seem to work
    return {
        "startupinfo": startupinfo,
        "creationflags": creationflags,
        "preexec_fn": preexec_fn,
    } 
开发者ID:openatx,项目名称:adbutils,代码行数:22,代码来源:_utils.py

示例5: run

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def run(cmd, close_in_child, keep_in_child, with_pgrp=True):
	child = os.fork()
	if child:
		return child
	if with_pgrp:
		os.setpgrp() # this pgrp is killed if the job fails
	for fd in close_in_child:
		os.close(fd)
	keep_in_child = set(keep_in_child)
	keep_in_child.add(int(os.getenv('BD_STATUS_FD')))
	keep_in_child.add(int(os.getenv('BD_TERM_FD')))
	close_fds(keep_in_child)
	# unreadable stdin - less risk of stuck jobs
	devnull = os.open('/dev/null', os.O_RDONLY)
	os.dup2(devnull, 0)
	os.close(devnull)
	if PY3:
		keep_in_child.update([1, 2])
		for fd in keep_in_child:
			os.set_inheritable(fd, True)
	os.execv(cmd[0], cmd)
	os._exit() 
开发者ID:eBay,项目名称:accelerator,代码行数:24,代码来源:dispatch.py

示例6: tcpdump_to_file

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def tcpdump_to_file(self,filename='capture.pcap',params='', timeout='10s'):
        """ Uses tcpdump (for packet capture) and wait

        The keyword ignores detail output of the command.
        By default, the keyword only captures 10s
        """
        BuiltIn().log('Run tcpdump command')
        result_file = '%s/%s' % (Common.get_result_path(),filename)
        cmd = 'sudo /usr/sbin/tcpdump %s -w %s' % (params,result_file)
        proc1 = subprocess.Popen(cmd,stderr=subprocess.STDOUT,stdout=subprocess.PIPE,shell=True,preexec_fn=os.setpgrp)
        time.sleep(DateTime.convert_time(timeout))

        output2 = subprocess.check_output('sudo /bin/kill %s' % proc1.pid,shell=True)
        time.sleep(1)
        output1 = b'\n'.join(proc1.stdout.readlines())
        BuiltIn().log(output1)
        BuiltIn().log(output2)

        # change owner of the captured file
        username = Common.current_username()
        usergroup = Common.current_usergroup()
        output = subprocess.check_output('sudo /bin/chown %s:%s %s' % (username,usergroup,result_file),shell=True)

        BuiltIn().log('Executed tcpdump command `%s`' % cmd) 
开发者ID:bachng2017,项目名称:RENAT,代码行数:26,代码来源:Tool.py

示例7: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def __init__(self, cmd, cwd=None, env=None):
        self._cmd = cmd
        self._cwd = cwd

        # Create process with new process group
        # Sending a signal to a process group will send it to all children
        # Hopefully this way no orphaned processes will be left behind
        self._process = subprocess.Popen(
            self._cmd,
            cwd=self._cwd,
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            universal_newlines=True,
            shell=True,
            bufsize=0,
            # Create new process group on POSIX, setpgrp does not exist on Windows
            #preexec_fn=os.setsid)
            preexec_fn=os.setpgrp)  # pylint: disable=no-member
        LOGGER.debug("Started process with pid=%i: '%s'", self._process.pid, (" ".join(self._cwd)))

        self._queue = InterruptableQueue()
        self._reader = AsynchronousFileReader(self._process.stdout, self._queue)
        self._reader.start() 
开发者ID:zhajio1988,项目名称:YASA,代码行数:26,代码来源:ostools.py

示例8: start_recording

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def start_recording(self):
		if self.get_status() not in ("REC", "PLAY+REC"):
			logging.info("STARTING NEW MIDI RECORD ...")
			try:
				cmd=self.sys_dir +"/sbin/jack-smf-recorder.sh --port {}".format(self.jack_record_port)
				#logging.info("COMMAND: %s" % cmd)
				self.rec_proc=Popen(cmd.split(" "), shell=True, preexec_fn=os.setpgrp)
				sleep(0.2)
			except Exception as e:
				logging.error("ERROR STARTING MIDI RECORD: %s" % e)
				self.zyngui.show_info("ERROR STARTING MIDI RECORD:\n %s" % e)
				self.zyngui.hide_info_timer(5000)

			self.update_list()
			return True

		else:
			return False 
开发者ID:zynthian,项目名称:zynthian-ui,代码行数:20,代码来源:zynthian_gui_midi_recorder.py

示例9: __enter__

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def __enter__(self):
        # The os.setpgrp() is passed in the argument preexec_fn so
        # it's run after the fork() and before  exec() to run the shell.
        my_env = os.environ.copy()
        for k, v in self.extra_env_vars.items():
            print('setting %s=%s (expanded to "%s") in environment' % (k, v, os.path.expandvars(str(v))))
            # Allow updates like PATH='/foo/bar/:$PATH'
            my_env[k] = os.path.expandvars(str(v))
        print 'command:', self.cmd
        self.proc = sp.Popen(self.cmd, shell=True, env=my_env, preexec_fn=os.setpgrp)
        time.sleep(5)  # give process a little time to start
        return self.proc 
开发者ID:thompsonb,项目名称:DL4MT,代码行数:14,代码来源:pyro_utils.py

示例10: start

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def start(self):
        """Starts the external measurement program."""
        assert (
            not self.is_running()
        ), "Attempted to start an energy measurement while one was already running."

        self._measurement_process = subprocess.Popen(
            [self._executable, "-r"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            bufsize=10000,
            preexec_fn=os.setpgrp,  # Prevent delivery of Ctrl+C to subprocess
        ) 
开发者ID:sosy-lab,项目名称:benchexec,代码行数:15,代码来源:intel_cpu_energy.py

示例11: preexec

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def preexec():
	os.setpgrp()

#--------------------------------------------------------------------------
# CLASS FOR GDB-LIKE ADAPTERS
#-------------------------------------------------------------------------- 
开发者ID:Vector35,项目名称:debugger,代码行数:8,代码来源:gdblike.py

示例12: preexec_function

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def preexec_function():
    os.setpgrp() 
开发者ID:WLANThermo,项目名称:WLANThermo_v2,代码行数:4,代码来源:wlt_2_nextion.py

示例13: _start_worker

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def _start_worker(self):
        env = dict(os.environ)
        env["ABUSEHELPER_SUBPROCESS"] = ""

        # Find out the full package & module name. Don't refer to the
        # variable __loader__ directly to keep flake8 (version 2.5.0)
        # linter happy.
        fullname = globals()["__loader__"].fullname

        own_conn, other_conn = native_socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
        try:
            process = subprocess.Popen(
                [sys.executable, "-m", fullname],
                preexec_fn=os.setpgrp,
                stdin=other_conn.fileno(),
                close_fds=True,
                env=env
            )

            try:
                conn = socket.fromfd(own_conn.fileno(), socket.AF_UNIX, socket.SOCK_STREAM)
            except:
                process.terminate()
                process.wait()
                raise
        finally:
            own_conn.close()
            other_conn.close()
        return process, conn 
开发者ID:abusesa,项目名称:abusehelper,代码行数:31,代码来源:roomgraph.py

示例14: start_viewer

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def start_viewer():
    cmd = [sys.executable, '-m', 'bag.io.gui']
    devnull = open(os.devnull, 'w')
    proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=devnull,
                            stderr=subprocess.STDOUT,
                            preexec_fn=os.setpgrp)
    return proc 
开发者ID:ucb-art,项目名称:BAG_framework,代码行数:9,代码来源:gui.py

示例15: execute

# 需要导入模块: import os [as 别名]
# 或者: from os import setpgrp [as 别名]
def execute(command_line, working_directory, stdout, stderr):
    preexec_fn = None
    if not (platform.system() == 'Windows'):
        preexec_fn = os.setpgrp
    proc = Popen(args=command_line,
                 shell=True,
                 cwd=working_directory,
                 stdout=stdout,
                 stderr=stderr,
                 preexec_fn=preexec_fn)
    return proc 
开发者ID:galaxyproject,项目名称:pulsar,代码行数:13,代码来源:unqueued.py


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