コード例 #1
1
ファイル: prociolog.py プロジェクト: whilp/prociolog
 def __init__(self, args, logger, **kwargs):
     _kwargs = kwargs.copy()
     for fdname in self.fdnames:
         _kwargs[fdname] = PIPE
     Popen.__init__(self, args, **_kwargs)
     self.logger = logger
     self.wrapfds()
コード例 #2
0
    def __init__(self, main_window, argv=sys.argv):
        Popen.__init__(self, ["python.exe", '-m'])
        # self.subprocess = AppViewer.SubProcessAppViewer(self)

        self._argv = argv
        self._main_window = main_window
        self.proc = None
コード例 #3
0
ファイル: mon_test.py プロジェクト: eugpermar/rb_monitor
 def __init__(self, args, wait_for_traps_listener_port=0, **kwargs):
     ''' Creates child and (optionally) waits for trap listener ready '''
     Popen.__init__(self, args,
                    **{**kwargs, 'stdout': PIPE, 'stderr': PIPE})
     if wait_for_traps_listener_port > 0:
         self.__wait_for_trap_listener(
                                 expected_port=wait_for_traps_listener_port)
コード例 #4
0
    def __init__(self,
                 args,
                 close_fds=False,
                 cwd=None,
                 env=None,
                 deathSignal=0,
                 childUmask=None,
                 stdin=PIPE,
                 stdout=PIPE,
                 stderr=PIPE):
        if not isinstance(args, list):
            args = list(args)

        if env is not None and not isinstance(env, list):
            env = list(("=".join(item) for item in env.iteritems()))

        self._childUmask = childUmask
        self._deathSignal = int(deathSignal)
        Popen.__init__(self,
                       args,
                       close_fds=close_fds,
                       cwd=cwd,
                       env=env,
                       stdin=stdin,
                       stdout=stdout,
                       stderr=stderr)
コード例 #5
0
ファイル: bithordetest.py プロジェクト: rawler/bithorde
    def __init__(self, label='bithorded', bithorded=os.environ.get('BITHORDED', 'bithorded'), config={}):
        cmd = ['stdbuf', '-o0', '-e0', bithorded, '-c', '/dev/stdin', '--log.level=TRACE']
        Popen.__init__(self, cmd, stderr=STDOUT, stdout=PIPE, stdin=PIPE)
        self._cleanup = list()
        if hasattr(config, 'setdefault'):
            suffix = (time(), os.getpid())
            server_cfg = config.setdefault('server', {})
            server_cfg.setdefault('tcpPort', 0)
            server_cfg.setdefault('inspectPort', 0)
            server_cfg.setdefault('unixSocket', "bhtest-sock-%d-%d" % suffix)
            self._cleanup.append(lambda: os.unlink(server_cfg['unixSocket']))
            cache_cfg = config.setdefault('cache', {})
            if 'dir' not in cache_cfg:
                from shutil import rmtree
                d = 'bhtest-cache-%d-%d' % suffix
                self._cleanup.append(lambda: rmtree(d, ignore_errors=True))
                os.mkdir(d)
                cache_cfg['dir'] = d

        self.buffer = LineBuffer(label, self.stdout)
        self.config = config
        self.label = label
        self.started = False

        self._run()
コード例 #6
0
 def __init__(self, args, ready=None, timeout=30, skip_valgrind=False, **kwargs):
     """Start an example process"""
     args = list(args)
     if platform.system() == "Windows":
         args[0] += ".exe"
     self.timeout = timeout
     self.args = args
     self.out = ""
     if not skip_valgrind:
         args = self.env_args + args
     try:
         Popen.__init__(self, args, stdout=PIPE, stderr=STDOUT,
                        universal_newlines=True,  **kwargs)
     except Exception as e:
         raise ProcError(self, str(e))
     # Start reader thread.
     self.pattern = ready
     self.ready = Event()
     # Help with Python 2.5, 2.6, 2.7 changes to Event.wait(), Event.is_set
     self.ready_set = False
     self.error = None
     self.thread = Thread(target=self.run_)
     self.thread.daemon = True
     self.thread.start()
     if self.pattern:
         self.wait_ready()
コード例 #7
0
 def __init__(self, args, valgrind=True, helgrind=False, **kwargs):
     """Start an example process"""
     self.args = list(args)
     self.kwargs = kwargs
     self._out = tempfile.TemporaryFile(mode='w+')
     valgrind_exe = valgrind and os.getenv("VALGRIND")
     if valgrind_exe:
         # run valgrind for speed, not for detailed information
         vg = [valgrind_exe]
         if helgrind:
             vg += ["--tool=helgrind", "--quiet", "--error-exitcode=42"]
         else:
             vg += ["--tool=memcheck"
                    ] + os.getenv("VALGRIND_ARGS").split(' ')
         self.args = vg + self.args
     if os.getenv("PROCTEST_VERBOSE"):
         sys.stderr.write("\n== running == " + " ".join(self.args) + "\n")
     try:
         Popen.__init__(self,
                        self.args,
                        stdout=self._out,
                        stderr=STDOUT,
                        **kwargs)
     except OSError as e:
         if e.errno == errno.ENOENT:
             raise NotFoundError(self, str(e))
         raise ProcError(self, str(e))
     except Exception as e:
         raise ProcError(self, str(e))
コード例 #8
0
ファイル: recipe-576957.py プロジェクト: jacob-carrier/code
    def __init__(self, argv, map=None, timeout=None, close_when_done=True,
            stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=None, bufsize=0, **popen_keyw):
        """Accepts all the same arguments and keywords as `subprocess.Popen`.
        Input or outputs specified as `PIPE` (now the default) for are wrapped
        in an asynchronous pipe dispatcher.

        The timeout is used to create an alarm, which can be cancelled by
        calling `cancel_timeout()`, `communicate()`, `wait()` or `kill()`.
        """
        Observable.__init__(self)
        self._map = map
        # Create the subprocess itself, wrapping preexec_fn in the clear_signals call
        Popen.__init__(self, argv, preexec_fn=lambda: self.clear_signals(preexec_fn),
                stdin=stdin, stdout=stdout, stderr=stderr, **popen_keyw)
        # Set the timeout on the subprocess.  If it fails, ignore the failure.
        try:
            fto = float(timeout)
            self._alarmobj = alarm.alarm(fto, self.kill) if fto > 0 else None
        except:
            self._alarmobj = None
        # Wrap the pipe I/O. Sets the Popen and pipe buffer sizes the same; perhaps not optimal.
        if stdout == PIPE:
            self.stdout = OutputPipeDispatcher(self.stdout, map=map, ignore_broken_pipe=True,
                    universal_newlines=self.universal_newlines, maxdata=bufsize)
            self.stdout.obs_add(self._pipe_event)
        if stderr == PIPE:
            self.stderr = OutputPipeDispatcher(self.stderr, map=map, ignore_broken_pipe=True,
                    universal_newlines=self.universal_newlines, maxdata=bufsize)
            self.stderr.obs_add(self._pipe_event)
        if stdin == PIPE:
            self.stdin = InputPipeDispatcher(self.stdin, map=map, ignore_broken_pipe=True,
                    close_when_done=close_when_done, maxdata=bufsize)
            self.stdin.obs_add(self._pipe_event)
コード例 #9
0
ファイル: bithordetest.py プロジェクト: loffeloffe/bithorde
    def __init__(self,
                 label='bithorded',
                 bithorded=os.environ.get('BITHORDED', 'bithorded'),
                 config={}):
        Popen.__init__(self,
                       ['stdbuf', '-o0', '-e0', bithorded, '-c', '/dev/stdin'],
                       stderr=STDOUT,
                       stdout=PIPE,
                       stdin=PIPE)
        self._cleanup = list()
        if hasattr(config, 'setdefault'):
            suffix = (time(), os.getpid())
            server_cfg = config.setdefault('server', {})
            server_cfg.setdefault('tcpPort', 0)
            server_cfg.setdefault('inspectPort', 0)
            server_cfg.setdefault('unixSocket', "bhtest-sock-%d-%d" % suffix)
            self._cleanup.append(lambda: os.unlink(server_cfg['unixSocket']))
            cache_cfg = config.setdefault('cache', {})
            if 'dir' not in cache_cfg:
                from shutil import rmtree
                d = 'bhtest-cache-%d-%d' % suffix
                self._cleanup.append(lambda: rmtree(d, ignore_errors=True))
                os.mkdir(d)
                cache_cfg['dir'] = d

        self.buffer = LineBuffer(label, self.stdout)
        self.config = config
        self.label = label
        self.started = False

        self._run()
コード例 #10
0
ファイル: ptrace.py プロジェクト: bhuztez/gulag
    def __init__(self, args, executable=None,
                 stdin=None, stdout=None, stderr=None,
                 cwd=None, env={},
                 time_limit=None, rss_limit=None, vm_limit=None):
        self._time_limit = time_limit
        self._rss_limit = rss_limit
        self._vm_limit = vm_limit

        self.cputime = None
        self.maxrss = 0
        self.maxvm = 0
        self.verdict = None

        Popen.__init__(
            self, args, bufsize=-1, executable=executable,
            stdin=stdin, stdout=stdout, stderr=stderr, close_fds=True,
            preexec_fn=self._preexec_hook, cwd=cwd, env=env)

        _, status = waitpid(self.pid, WUNTRACED)

        assert WIFSTOPPED(status), "cannot start subprocess"

        if WSTOPSIG(status) != SIGTRAP:
            self.kill()
            self.wait()
            assert False, "subprocess stopped unexpectedly"
コード例 #11
0
ファイル: proctest.py プロジェクト: chradcliffe/qpid-proton
 def __init__(self, args, valgrind=True, helgrind=False, **kwargs):
     """Start an example process"""
     self.args = list(args)
     self.kwargs = kwargs
     self._out = tempfile.TemporaryFile()
     valgrind_exe = valgrind and os.getenv("VALGRIND")
     if valgrind_exe:
         # run valgrind for speed, not for detailed information
         vg = [
             valgrind_exe, "--quiet", "--num-callers=2",
             "--error-exitcode=%s" % self.valgrind_exit
         ]
         if helgrind:
             vg += ["--tool=helgrind", "--history-level=none"]
         else:
             vg += [
                 "--tool=memcheck", "--leak-check=full",
                 "--leak-resolution=low"
             ]
         self.args = vg + self.args
         self._out.flush()
     try:
         Popen.__init__(self,
                        self.args,
                        stdout=self._out,
                        stderr=STDOUT,
                        **kwargs)
     except OSError, e:
         if e.errno == errno.ENOENT:
             raise NotFoundError(self, str(e))
         raise ProcError(self, str(e))
コード例 #12
0
ファイル: buffered_io.py プロジェクト: cpcloud/binstar-build
    def __init__(self, args, stdout=None, iotimeout=None, timeout=None, **kwargs):
        self._output = stdout

        Popen.__init__(self, args, stdout=PIPE, stderr=STDOUT,
                       **kwargs)

        self._iostream = IOStream(self.stdout, self._output, iotimeout, timeout, self.timeout_callback)
        self._iostream.start()
コード例 #13
0
ファイル: recipe-576957.py プロジェクト: zlrs/code-1
    def __init__(self,
                 argv,
                 map=None,
                 timeout=None,
                 close_when_done=True,
                 stdin=PIPE,
                 stdout=PIPE,
                 stderr=PIPE,
                 preexec_fn=None,
                 bufsize=0,
                 **popen_keyw):
        """Accepts all the same arguments and keywords as `subprocess.Popen`.
        Input or outputs specified as `PIPE` (now the default) for are wrapped
        in an asynchronous pipe dispatcher.

        The timeout is used to create an alarm, which can be cancelled by
        calling `cancel_timeout()`, `communicate()`, `wait()` or `kill()`.
        """
        Observable.__init__(self)
        self._map = map
        # Create the subprocess itself, wrapping preexec_fn in the clear_signals call
        Popen.__init__(self,
                       argv,
                       preexec_fn=lambda: self.clear_signals(preexec_fn),
                       stdin=stdin,
                       stdout=stdout,
                       stderr=stderr,
                       **popen_keyw)
        # Set the timeout on the subprocess.  If it fails, ignore the failure.
        try:
            fto = float(timeout)
            self._alarmobj = alarm.alarm(fto, self.kill) if fto > 0 else None
        except:
            self._alarmobj = None
        # Wrap the pipe I/O. Sets the Popen and pipe buffer sizes the same; perhaps not optimal.
        if stdout == PIPE:
            self.stdout = OutputPipeDispatcher(
                self.stdout,
                map=map,
                ignore_broken_pipe=True,
                universal_newlines=self.universal_newlines,
                maxdata=bufsize)
            self.stdout.obs_add(self._pipe_event)
        if stderr == PIPE:
            self.stderr = OutputPipeDispatcher(
                self.stderr,
                map=map,
                ignore_broken_pipe=True,
                universal_newlines=self.universal_newlines,
                maxdata=bufsize)
            self.stderr.obs_add(self._pipe_event)
        if stdin == PIPE:
            self.stdin = InputPipeDispatcher(self.stdin,
                                             map=map,
                                             ignore_broken_pipe=True,
                                             close_when_done=close_when_done,
                                             maxdata=bufsize)
            self.stdin.obs_add(self._pipe_event)
コード例 #14
0
ファイル: bt.py プロジェクト: binoyjayan/utilities
  def __init__(self, hide_stderr=False):
    stderr_file = open('/dev/null','w') if hide_stderr else None
    Popen.__init__(self, ['gdb'],
                   stdin=PIPE, stdout=PIPE, stderr=stderr_file)

    self._buffer = ''
    self.read_until_prompt()
    
    self.cmd('set print elements 0')
    self.cmd('set width 0')
コード例 #15
0
    def __init__(self, command, *args, **options):
        args = (command, ) + args
        options.setdefault('stdout', PIPE)
        options.setdefault('stderr', STDOUT)

        if isinstance(options['stdout'], basestring):
            options['stdout'] = open(options['stdout'], 'w')

        self.daemon = options.pop('daemon', True)
        Popen.__init__(self, args, **options)
コード例 #16
0
ファイル: windows.py プロジェクト: lovrop/mini-grader
 def __init__ (self, *args, **keywords):
     self.time = 0
     self.vmpeak = 0
     self.timeout = False
     self.memout = False
     self.path = args[0]
     Popen.__init__(self, *args, **keywords)
     PROCESS_QUERY_INFORMATION = 0x0400
     PROCESS_VM_READ = 0x0010
     self.hProcess = ctypes.windll.kernel32.OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, False, self.pid)
コード例 #17
0
 def __init__(self, *args, **keywords):
     self.time = 0
     self.vmpeak = 0
     self.timeout = False
     self.memout = False
     self.path = args[0]
     Popen.__init__(self, *args, **keywords)
     PROCESS_QUERY_INFORMATION = 0x0400
     PROCESS_VM_READ = 0x0010
     self.hProcess = ctypes.windll.kernel32.OpenProcess(
         PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, False, self.pid)
コード例 #18
0
ファイル: popen.py プロジェクト: GuillaumeFromage/my-gozerbot
 def __init__(self, args):
     Popen.__init__(self,
                    args,
                    shell=False,
                    stdin=PIPE,
                    stdout=PIPE,
                    stderr=PIPE,
                    close_fds=True)
     self.fromchild = self.stdout
     self.tochild = self.stdin
     self.errors = self.stderr
コード例 #19
0
ファイル: kernels.py プロジェクト: dwyde/poolside
 def __init__(self, command, filename, preexec_fn=_setlimits):
     """Class constructor.
     
     :param command: A command to run, e.g., "python".
     :param filename: A script file to pass to the `command`.
     :param preexec_fn: A function to call in the child process.
     """
     
     self.arg_list = [command, filename]
     Popen.__init__(self, self.arg_list, stdout=PIPE, stdin=PIPE,
             preexec_fn=preexec_fn)
コード例 #20
0
 def start(self):
     if self.DEBUG:
         printe(' '.join(
             ["'" + arg + "'" if ' ' in arg else arg for arg in self.args]))
     from subprocess import PIPE
     Popen.__init__(self,
                    self.args,
                    stdin=PIPE,
                    stdout=PIPE,
                    stderr=PIPE,
                    universal_newlines=True)
コード例 #21
0
ファイル: mplayer.py プロジェクト: sevra/python-mplayer
 def run(self):
    Popen.__init__(self, [self.path, '-idle', '-slave', '-quiet']+self.args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
    self.manager = Manager()
    self.defaults = self.manager.dict()
    self._state = Value('i')
    self._state.value = STOPPED
    self.notifier = SelectQueue()
    self.calls = SelectQueue()
    self.results = Queue()
    self.ioworker = IOWorker(self.stdin, self.stdout, self._state, self.notifier, self.calls, self.results)
    self.ioworker.start()
コード例 #22
0
 def __init__(self, host, nodes):
     self.host = host
     self.nodes = nodes
     self.out = None
     self.err = None
     self._pids = None
     self._cond = Condition()
     self._pids_thread = Thread(target=self._pids_thread_target)
     args = ['ssh', host, 'python3', os.path.join(os.getcwd(), 'launch.py')]
     args.extend(['{}:{}:{}'.format(i, host, p) for i, p in nodes.items()])
     Popen.__init__(self, args, stdout=PIPE, stderr=PIPE)
     self._pids_thread.start()
コード例 #23
0
    def __init__(self,
                 args,
                 stdout=None,
                 iotimeout=None,
                 timeout=None,
                 **kwargs):
        self._output = stdout

        Popen.__init__(self, args, stdout=PIPE, stderr=STDOUT, **kwargs)

        self._iostream = IOStream(self.stdout, self._output, iotimeout,
                                  timeout, self.timeout_callback)
        self._iostream.start()
コード例 #24
0
ファイル: __init__.py プロジェクト: edwardbadboy/vdsm-ubuntu
    def __init__(self, args, close_fds=False, cwd=None, env=None,
                 deathSignal=0):
        if not isinstance(args, list):
            args = list(args)

        if env is not None and not isinstance(env, list):
            env = list(("=".join(item) for item in env.iteritems()))

        self._deathSignal = int(deathSignal)
        Popen.__init__(self, args,
                       close_fds=close_fds, cwd=cwd, env=env,
                       stdin=PIPE, stdout=PIPE,
                       stderr=PIPE)
コード例 #25
0
ファイル: linux.py プロジェクト: tgracin/mini-grader
    def __init__ (self, *args, **keywords):
        self.time = 0
        self.vmpeak = 0
        self.timeout = False
        self.memout = False
        self.path = args[0]

        # Raise stack limit as high as it goes (hopefully unlimited)
        soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
        resource.setrlimit(resource.RLIMIT_STACK, (hard, hard))

        # Now start the process
        Popen.__init__(self, *args, **keywords)
コード例 #26
0
ファイル: example_test.py プロジェクト: ShaLei/qpid-proton
 def __init__(self, args, ready=None, timeout=30, skip_valgrind=False, **kwargs):
     """Start an example process"""
     args = list(args)
     if platform.system() == "Windows":
         args[0] += ".exe"
     self.timeout = timeout
     self.args = args
     self.out = ""
     if not skip_valgrind:
         args = self.env_args + args
     try:
         Popen.__init__(self, args, stdout=PIPE, stderr=STDOUT, **kwargs)
     except Exception, e:
         raise ProcError(self, str(e))
コード例 #27
0
 def __init__(self, args, **kwargs):
     """Start an example process"""
     args = list(args)
     self.args = args
     self._out = os.tmpfile()
     try:
         Popen.__init__(self,
                        self.env_args + self.args,
                        stdout=self._out,
                        stderr=STDOUT,
                        **kwargs)
     except OSError, e:
         if e.errno == errno.ENOENT:
             raise NotFoundError(self, str(e))
         raise ProcError(self, str(e))
コード例 #28
0
ファイル: psutil.py プロジェクト: tgracin/mini-grader
    def __init__(self, *args, **keywords):
        self.time = 0
        self.vmpeak = 0
        self.timeout = False
        self.memout = False
        self._aborted = False
        self._abort_lock = threading.Lock()
        self._abort_cv = threading.Condition(self._abort_lock)
        self.on_osx = sys.platform.startswith('darwin')

        self._set_stack_limit()

        # Now start the process
        Popen.__init__(self, *args, **keywords)

        self.psutil_process = psutil.Process(self.pid)
コード例 #29
0
	def run(self):
		from subprocess import PIPE
		rout = self.return_stdout
		rerr = self.return_stderr
		Popen.__init__(self,
			self.args,
			stdout=self.custom_stdout or (PIPE if rout else None),
			stderr=PIPE if rerr else None,
			universal_newlines=True
		)
		self.wait()
		if self.returncode != 0: raise CmdError(self)
		if self.return_self: return self
		elif rout and rerr: return self.stdout.read(), self.stderr.read()
		elif rout: return self.stdout.read()
		elif rerr: return self.stderr.read()
コード例 #30
0
ファイル: mplayer.py プロジェクト: sevra/python-mplayer
 def run(self):
     Popen.__init__(self,
                    [self.path, '-idle', '-slave', '-quiet'] + self.args,
                    stdin=PIPE,
                    stdout=PIPE,
                    stderr=PIPE)
     self.manager = Manager()
     self.defaults = self.manager.dict()
     self._state = Value('i')
     self._state.value = STOPPED
     self.notifier = SelectQueue()
     self.calls = SelectQueue()
     self.results = Queue()
     self.ioworker = IOWorker(self.stdin, self.stdout, self._state,
                              self.notifier, self.calls, self.results)
     self.ioworker.start()
コード例 #31
0
ファイル: AsyncProcess.py プロジェクト: varesa/rpmmanage
 def __init__(self, args, map=None, stdin=PIPE, stdout=PIPE, stderr=PIPE,
              callback=None, maxwrite=512, maxread=1024, **keywmap):
     """Init the subprocess object, wrapping the standard I/O pipes in
     dispatchers.  Note that the defaults are changed to PIPE for all I/O."""
     if map is None:
         self._map = process_map
     else:
         self._map = map
     self.__callback = callback
     Popen.__init__(self, args, stdin=stdin, stdout=stdout, stderr=stderr, **keywmap)
     self.add_subprocess(map)
     if self.stdin:
         self.stdin = StdInputHandler(self.stdin, self, maxdata=maxwrite)
     if self.stdout:
         self.stdout = StdOutputHandler(self.stdout, self, maxdata=maxread)
     if self.stderr:
         self.stderr = StdOutputHandler(self.stderr, self, maxdata=maxread)
コード例 #32
0
ファイル: base.py プロジェクト: cl4u2/radiomate
		def __init__(self, timeslot, mainpassword=""):
				cmd = config.LIQUIDSOAP + " -v - " # take commands from standard input 
				# spawn the process 
				Popen.__init__(self, shlex.split(cmd), bufsize=-1, universal_newlines=True, 
								stdin=PIPE, stdout=None, stderr=STDOUT)

				self.logger = logging.getLogger("radiomate.jukebox")
				logging.basicConfig(filename=config.LOGFILENAME, level=config.LOGGINGLEVEL)
				
				# initialize the connection to the database
				try:
						self.cm = dao.DBConnectionManager(dbhost = config.DBHOST,
										dbuser = config.DBUSER, dbpassword = config.DBPASSWORD,
										database = config.DATABASE)
						self.pldao = dao.PlayListDAO(self.cm)
				except Exception, e:
						raise JukeSlotException(str(e))
コード例 #33
0
ファイル: simple_rexec.py プロジェクト: Huitzilo/PyNN
 def run(self, node, quiet=True):
     self.node = node
     if node == this_host:
         launch_cmd = ''
     else:
         launch_cmd = "ssh -x %s" % node
     cmd = "%s %s %s %s" % (launch_cmd,
                            sys.executable,
                            os.path.abspath(self.script),
                            " ".join(self.args))
     print cmd        
     self._output = tempfile.TemporaryFile()
     if quiet:
         stdout = self._output
     else:
         stdout = None
     Popen.__init__(self, cmd, stdin=None, stdout=stdout, stderr=STDOUT,
                    shell=True)
コード例 #34
0
ファイル: exampletest.py プロジェクト: lavatory/qpid-proton
 def __init__(self, args, skip_valgrind=False, **kwargs):
     """Start an example process"""
     args = list(args)
     if skip_valgrind:
         self.args = args
     else:
         self.args = self.vg_args + args
     self.kwargs = kwargs
     self._out = os.tmpfile()
     try:
         Popen.__init__(self,
                        self.args,
                        stdout=self._out,
                        stderr=STDOUT,
                        **kwargs)
     except OSError, e:
         if e.errno == errno.ENOENT:
             raise NotFoundError(self, str(e))
         raise ProcError(self, str(e))
コード例 #35
0
ファイル: etcdwrap.py プロジェクト: sakurai-youhei/etcddump
    def __init__(self, **kwargs):
        self.host = "localhost"
        self.port = find_free_port()
        self.client_urls = ["http://{}:{}".format(self.host, self.port)]
        self.peer_urls = ["http://{}:{}".format(self.host, find_free_port())]

        tempdir = mkdtemp()
        register(rmtree, tempdir)
        kwargs["args"] = [EtcdWrap._etcd_,
                          "--debug",
                          "--data-dir", tempdir,
                          "--listen-client-urls",
                          ",".join(self.client_urls),
                          "--advertise-client-urls",
                          ",".join(self.client_urls),
                          "--listen-peer-urls",
                          ",".join(self.peer_urls)]
        kwargs["stderr"] = DEVNULL
        Popen.__init__(self, **kwargs)
コード例 #36
0
ファイル: __init__.py プロジェクト: oVirt/cpopen
    def __init__(self, args, close_fds=False, cwd=None, env=None,
                 deathSignal=0, childUmask=None,
                 stdin=PIPE, stdout=PIPE, stderr=PIPE,
                 restore_sigpipe=False):
        if not isinstance(args, list):
            args = list(args)

        self._childUmask = childUmask
        self._deathSignal = int(deathSignal)

        if SUPPORTS_RESTORE_SIGPIPE:
            kw = {'restore_sigpipe': restore_sigpipe}
        else:
            kw = {}

        Popen.__init__(self, args,
                       close_fds=close_fds, cwd=cwd, env=env,
                       stdin=stdin, stdout=stdout,
                       stderr=stderr,
                       **kw)
コード例 #37
0
ファイル: testutil.py プロジェクト: samwhitlock/msp
    def __init__(self, args, cpulimit=30, filesizelimit=500, stdinput=None,
                 **keys):
        self.results = None
        self.tempout = self.temperr = self.tempin = None

        args = "limited-exec %s %s %s" % (cpulimit, filesizelimit, args)

        if keys.get('stdout', None) or PIPE == PIPE:
            self.tempout = mkstemp()
            keys['stdout'] = self.tempout[0]
        if keys.get('stderr', None) or PIPE == PIPE:
            self.temperr = mkstemp()
            keys['stderr'] = self.temperr[0]
        if stdinput is not None:
            self.tempin = mkstemp()
            os.write(self.tempin[0], stdinput)
            os.lseek(self.tempin[0], 0, 0)
            keys['stdin'] = self.tempin[0]

        Popen.__init__ (self, re.split(r'\s+', args),  **keys)
コード例 #38
0
ファイル: simple_rexec.py プロジェクト: agravier/pynn
 def run(self, node, quiet=True):
     self.node = node
     if node == this_host:
         launch_cmd = ''
     else:
         launch_cmd = "ssh -x %s" % node
     cmd = "%s %s %s %s" % (launch_cmd, sys.executable,
                            os.path.abspath(self.script), " ".join(
                                self.args))
     print cmd
     self._output = tempfile.TemporaryFile()
     if quiet:
         stdout = self._output
     else:
         stdout = None
     Popen.__init__(self,
                    cmd,
                    stdin=None,
                    stdout=stdout,
                    stderr=STDOUT,
                    shell=True)
コード例 #39
0
    def __init__(self, size=(1024,768), color_depth=24, bgcolor='black', **kwargs):
        self.color_depth = color_depth
        self.size = size
        self.bgcolor = bgcolor
        self.screen = 0
        self.process = None
        self.display = None

        mutex.acquire()
        try:
            self.display = self.get_next_free_display()
            while self.display in USED_DISPLAY_NUMBER_LIST:
                self.display += 1
            USED_DISPLAY_NUMBER_LIST.append(self.display)
        finally:
            mutex.release()

        Popen.__init__(self,self._cmd);

        self.redirect_display(True)
        time.sleep(0.1)
コード例 #40
0
 def __init__(
     self,
     args,
     stdin: PopenStdArg = None,
     stdout: PopenStdArg = None,
     stderr: PopenStdArg = None,
     **kwargs,
 ) -> None:
     Popen.__init__(cast(Popen, self),
                    args,
                    stdin=stdin,
                    stdout=stdout,
                    stderr=stderr,
                    **kwargs)
     EventManager.__init__(self)
     # Construct a dict of name=(stream, wrapper, is_pipe) for std streams
     self._name = " ".join(args)
     self._std = dict((name, [stream, None, desc == PIPE])
                      for name, desc, stream in zip(
                          ("stdin", "stdout", "stderr"),
                          (stdin, stdout, stderr),
                          (self.stdin, self.stdout, self.stderr),
                      ))
     self._iterator: Optional[Iterator[str]] = None
コード例 #41
0
ファイル: process.py プロジェクト: Fairvol/SublimeCodeIntel
    def __init__(self, cmd, cwd=None, env=None, flags=None,
                 stdin=PIPE, stdout=PIPE, stderr=PIPE,
                 universal_newlines=True):
        """Create a child process.

        "cmd" is the command to run, either a list of arguments or a string.
        "cwd" is a working directory in which to start the child process.
        "env" is an environment dictionary for the child.
        "flags" are system-specific process creation flags. On Windows
            this can be a bitwise-OR of any of the win32process.CREATE_*
            constants (Note: win32process.CREATE_NEW_PROCESS_GROUP is always
            OR'd in). On Unix, this is currently ignored.
        "stdin", "stdout", "stderr" can be used to specify file objects
            to handle read (stdout/stderr) and write (stdin) events from/to
            the child. By default a file handle will be created for each
            io channel automatically, unless set explicitly to None. When set
            to None, the parent io handles will be used, which can mean the
            output is redirected to Komodo's log files.
        "universal_newlines": On by default (the opposite of subprocess).
        """
        self.__use_killpg = False
        auto_piped_stdin = False
        preexec_fn = None
        shell = False
        if not isinstance(cmd, (list, tuple)):
            # The cmd is the already formatted, ready for the shell. Otherwise
            # subprocess.Popen will treat this as simply one command with
            # no arguments, resulting in an unknown command.
            shell = True
        if sys.platform.startswith("win"):
            # On Windows, cmd requires some special handling of multiple quoted
            # arguments, as this is what cmd will do:
            #    See if the first character is a quote character and if so,
            #    strip the leading character and remove the last quote character
            #    on the command line, preserving any text after the last quote
            #    character.
            if cmd and shell and cmd.count('"') > 2:
                if not cmd.startswith('""') or not cmd.endswith('""'):
                    # Needs to be a re-quoted with additional double quotes.
                    # http://bugs.activestate.com/show_bug.cgi?id=75467
                    cmd = '"%s"' % (cmd, )

            # XXX - subprocess needs to be updated to use the wide string API.
            # subprocess uses a Windows API that does not accept unicode, so
            # we need to convert all the environment variables to strings
            # before we make the call. Temporary fix to bug:
            #   http://bugs.activestate.com/show_bug.cgi?id=72311
            if env:
                encoding = sys.getfilesystemencoding()
                _enc_env = {}
                for key, value in env.items():
                    try:
                        _enc_env[key.encode(encoding)] = value.encode(encoding)
                    except UnicodeEncodeError:
                        # Could not encode it, warn we are dropping it.
                        log.warn("Could not encode environment variable %r "
                                 "so removing it", key)
                env = _enc_env

            if flags is None:
                flags = CREATE_NO_WINDOW

            # If we don't have standard handles to pass to the child process
            # (e.g. we don't have a console app), then
            # `subprocess.GetStdHandle(...)` will return None. `subprocess.py`
            # handles that (http://bugs.python.org/issue1124861)
            #
            # However, if Komodo is started from the command line, then
            # the shell's stdin handle is inherited, i.e. in subprocess.py:
            #      p2cread = GetStdHandle(STD_INPUT_HANDLE)   # p2cread == 3
            # A few lines later this leads to:
            #    Traceback (most recent call last):
            #      ...
            #      File "...\lib\mozilla\python\komodo\process.py", line 130, in __init__
            #        creationflags=flags)
            #      File "...\lib\python\lib\subprocess.py", line 588, in __init__
            #        errread, errwrite) = self._get_handles(stdin, stdout, stderr)
            #      File "...\lib\python\lib\subprocess.py", line 709, in _get_handles
            #        p2cread = self._make_inheritable(p2cread)
            #      File "...\lib\python\lib\subprocess.py", line 773, in _make_inheritable
            #        DUPLICATE_SAME_ACCESS)
            #    WindowsError: [Error 6] The handle is invalid
            #
            # I suspect this indicates that the stdin handle inherited by
            # the subsystem:windows komodo.exe process is invalid -- perhaps
            # because of mis-used of the Windows API for passing that handle
            # through. The same error can be demonstrated in PythonWin:
            #   from _subprocess import *
            #   from subprocess import *
            #   h = GetStdHandle(STD_INPUT_HANDLE)
            #   p = Popen("python -c '1'")
            #   p._make_interitable(h)
            #
            # I don't understand why the inherited stdin is invalid for
            # `DuplicateHandle`, but here is how we are working around this:
            # If we detect the condition where this can fail, then work around
            # it by setting the handle to `subprocess.PIPE`, resulting in
            # a different and workable code path.
            if self._needToHackAroundStdHandles() \
               and not (flags & CREATE_NEW_CONSOLE):
                if stdin is None and sys.stdin \
                   and sys.stdin.fileno() not in (0, 1, 2):
                    stdin = PIPE
                    auto_piped_stdin = True
                if stdout is None and sys.stdout \
                   and sys.stdout.fileno() not in (0, 1, 2):
                    stdout = PIPE
                if stderr is None and sys.stderr \
                   and sys.stderr.fileno() not in (0, 1, 2):
                    stderr = PIPE
        else:
            # Set flags to 0, subprocess raises an exception otherwise.
            flags = 0
            # Set a preexec function, this will make the sub-process create it's
            # own session and process group - bug 80651, bug 85693.
            preexec_fn = os.setsid
            # Mark as requiring progressgroup killing. This will allow us to
            # later kill both the spawned shell and the sub-process in one go
            # (see the kill method) - bug 85693.
            self.__use_killpg = True

        # Internal attributes.
        self.__cmd = cmd
        self.__retval = None
        self.__hasTerminated = threading.Condition()

        # Launch the process.
        # print "Process: %r in %r" % (cmd, cwd)
        Popen.__init__(self, cmd, cwd=cwd, env=env, shell=shell,
                       stdin=stdin, stdout=stdout, stderr=stderr,
                       preexec_fn=preexec_fn,
                       universal_newlines=universal_newlines,
                       creationflags=flags)
        if auto_piped_stdin:
            self.stdin.close()
コード例 #42
0
ファイル: TestUtils.py プロジェクト: Sciumo/Accumulo
 def __init__(self, cmd, **args):
    self.cmd = cmd
    BasePopen.__init__(self, cmd, **args)
コード例 #43
0
ファイル: osx_common.py プロジェクト: szhu/osx-pyutils
    def start(self):
        if self.DEBUG:
            printe(" ".join(["'" + arg + "'" if " " in arg else arg for arg in self.args]))
        from subprocess import PIPE

        Popen.__init__(self, self.args, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
コード例 #44
0
ファイル: geventpopen.py プロジェクト: jbenet/py-bsonnetwork
 def __init__(self, *args, **kwargs):
     _Popen.__init__(self, *args, **kwargs)
     if self.stdin is not None:
         self.stdin = GeventFile(self.stdin)
     if self.stdout is not None:
         self.stdout = GeventFile(self.stdout)
コード例 #45
0
ファイル: popen.py プロジェクト: buzzworkers/tl
 def __init__(self, args):
     Popen.__init__(self, args, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
     self.fromchild = self.stdout
     self.tochild   = self.stdin
     self.errors    = self.stderr
コード例 #46
0
 def __init__(self, cmd, **args):
     self.cmd = cmd
     BasePopen.__init__(self, cmd, **args)
コード例 #47
0
ファイル: process.py プロジェクト: INDIAN2020/Sublime-text-2
    def __init__(self,
                 cmd,
                 cwd=None,
                 env=None,
                 flags=None,
                 stdin=PIPE,
                 stdout=PIPE,
                 stderr=PIPE,
                 universal_newlines=True):
        """Create a child process.

        "cmd" is the command to run, either a list of arguments or a string.
        "cwd" is a working directory in which to start the child process.
        "env" is an environment dictionary for the child.
        "flags" are system-specific process creation flags. On Windows
            this can be a bitwise-OR of any of the win32process.CREATE_*
            constants (Note: win32process.CREATE_NEW_PROCESS_GROUP is always
            OR'd in). On Unix, this is currently ignored.
        "stdin", "stdout", "stderr" can be used to specify file objects
            to handle read (stdout/stderr) and write (stdin) events from/to
            the child. By default a file handle will be created for each
            io channel automatically, unless set explicitly to None. When set
            to None, the parent io handles will be used, which can mean the
            output is redirected to Komodo's log files.
        "universal_newlines": On by default (the opposite of subprocess).
        """
        self.__use_killpg = False
        auto_piped_stdin = False
        preexec_fn = None
        shell = False
        if not isinstance(cmd, (list, tuple)):
            # The cmd is the already formatted, ready for the shell. Otherwise
            # subprocess.Popen will treat this as simply one command with
            # no arguments, resulting in an unknown command.
            shell = True
        if sys.platform.startswith("win"):
            # On Windows, cmd requires some special handling of multiple quoted
            # arguments, as this is what cmd will do:
            #    See if the first character is a quote character and if so,
            #    strip the leading character and remove the last quote character
            #    on the command line, preserving any text after the last quote
            #    character.
            if cmd and shell and cmd.count('"') > 2:
                if not cmd.startswith('""') or not cmd.endswith('""'):
                    # Needs to be a re-quoted with additional double quotes.
                    # http://bugs.activestate.com/show_bug.cgi?id=75467
                    cmd = '"%s"' % (cmd, )

            # XXX - subprocess needs to be updated to use the wide string API.
            # subprocess uses a Windows API that does not accept unicode, so
            # we need to convert all the environment variables to strings
            # before we make the call. Temporary fix to bug:
            #   http://bugs.activestate.com/show_bug.cgi?id=72311
            if env:
                encoding = sys.getfilesystemencoding()
                _enc_env = {}
                for key, value in env.items():
                    try:
                        _enc_env[key.encode(encoding)] = value.encode(encoding)
                    except UnicodeEncodeError:
                        # Could not encode it, warn we are dropping it.
                        log.warn(
                            "Could not encode environment variable %r "
                            "so removing it", key)
                env = _enc_env

            if flags is None:
                flags = CREATE_NO_WINDOW

            # If we don't have standard handles to pass to the child process
            # (e.g. we don't have a console app), then
            # `subprocess.GetStdHandle(...)` will return None. `subprocess.py`
            # handles that (http://bugs.python.org/issue1124861)
            #
            # However, if Komodo is started from the command line, then
            # the shell's stdin handle is inherited, i.e. in subprocess.py:
            #      p2cread = GetStdHandle(STD_INPUT_HANDLE)   # p2cread == 3
            # A few lines later this leads to:
            #    Traceback (most recent call last):
            #      ...
            #      File "...\lib\mozilla\python\komodo\process.py", line 130, in __init__
            #        creationflags=flags)
            #      File "...\lib\python\lib\subprocess.py", line 588, in __init__
            #        errread, errwrite) = self._get_handles(stdin, stdout, stderr)
            #      File "...\lib\python\lib\subprocess.py", line 709, in _get_handles
            #        p2cread = self._make_inheritable(p2cread)
            #      File "...\lib\python\lib\subprocess.py", line 773, in _make_inheritable
            #        DUPLICATE_SAME_ACCESS)
            #    WindowsError: [Error 6] The handle is invalid
            #
            # I suspect this indicates that the stdin handle inherited by
            # the subsystem:windows komodo.exe process is invalid -- perhaps
            # because of mis-used of the Windows API for passing that handle
            # through. The same error can be demonstrated in PythonWin:
            #   from _subprocess import *
            #   from subprocess import *
            #   h = GetStdHandle(STD_INPUT_HANDLE)
            #   p = Popen("python -c '1'")
            #   p._make_interitable(h)
            #
            # I don't understand why the inherited stdin is invalid for
            # `DuplicateHandle`, but here is how we are working around this:
            # If we detect the condition where this can fail, then work around
            # it by setting the handle to `subprocess.PIPE`, resulting in
            # a different and workable code path.
            if self._needToHackAroundStdHandles() \
               and not (flags & CREATE_NEW_CONSOLE):
                if stdin is None and sys.stdin \
                   and sys.stdin.fileno() not in (0,1,2):
                    stdin = PIPE
                    auto_piped_stdin = True
                if stdout is None and sys.stdout \
                   and sys.stdout.fileno() not in (0,1,2):
                    stdout = PIPE
                if stderr is None and sys.stderr \
                   and sys.stderr.fileno() not in (0,1,2):
                    stderr = PIPE
        else:
            # Set flags to 0, subprocess raises an exception otherwise.
            flags = 0
            # Set a preexec function, this will make the sub-process create it's
            # own session and process group - bug 80651, bug 85693.
            preexec_fn = os.setsid
            # Mark as requiring progressgroup killing. This will allow us to
            # later kill both the spawned shell and the sub-process in one go
            # (see the kill method) - bug 85693.
            self.__use_killpg = True

        # Internal attributes.
        self.__cmd = cmd
        self.__retval = None
        self.__hasTerminated = threading.Condition()

        # Launch the process.
        #print "Process: %r in %r" % (cmd, cwd)
        Popen.__init__(self,
                       cmd,
                       cwd=cwd,
                       env=env,
                       shell=shell,
                       stdin=stdin,
                       stdout=stdout,
                       stderr=stderr,
                       preexec_fn=preexec_fn,
                       universal_newlines=universal_newlines,
                       creationflags=flags)
        if auto_piped_stdin:
            self.stdin.close()
コード例 #48
0
ファイル: pager.py プロジェクト: fretboardfreak/code
 def __init__(self):
     Popen.__init__(self, ['less', '-FRX'], stdin=PIPE)
コード例 #49
0
 def __init__(self, arg, *args, **kwargs):
     if arg[:2] == [sys.executable, '-c']:
         assert len(arg) == 3, arg
         arg = arg[:2] + [monkey_patch + arg[2]]
     _Popen.__init__(self, arg, *args, **kwargs)
コード例 #50
0
 def __init__(self, arg, *args, **kwargs):
     if arg[:2] == [sys.executable, '-c']:
         assert len(arg) == 3, arg
         arg = arg[:2] + [monkey_patch + arg[2]]
     _Popen.__init__(self, arg, *args, **kwargs)
コード例 #51
0
 def __init__(self, *popen_args, **popen_kwargs):
     if sys.version_info.major ==2:
         return Popen.__init__(*popen_args, **popen_kwargs)
     if sys.version_info.major == 3 : 
         popen_kwargs['encoding'] = 'utf8'
     return Popen.__init__(*popen_args, **popen_kwargs)
コード例 #52
0
    def __init__(self, *args, **kwargs):
        self.timeout = kwargs.pop('timeout', 0)
        self.timer = None
        self.done = Event()

        Popen.__init__(self, *args, **kwargs)
コード例 #53
0
ファイル: local.py プロジェクト: weka-io/plumbum
 def __init__(self, *args, **kwargs):
     self.encoding = kwargs.pop("encoding", None)
     self.machine = kwargs.pop("machine", None)
     Popen.__init__(self, *args, **kwargs)
コード例 #54
0
ファイル: stupff.py プロジェクト: jonashaag/stupFF
 def __init__(self, *args, **kwargs):
     self._procname = args[0][0]
     Popen.__init__(self, *args, **kwargs)
コード例 #55
0
 def __init__(self, cargs, *args):
     Popen.__init__(self, cargs, *args, preexec_fn = preexec)
     self.args = cargs