예제 #1
0
    def test_process_kill(self):
        self.exit_cb_called = 0
        self.close_cb_called = 0
        self.exit_status = -1
        self.term_signal = 0

        def handle_close_cb(proc):
            self.close_cb_called += 1

        def proc_exit_cb(proc, exit_status, term_signal):
            self.exit_cb_called += 1
            self.exit_status = exit_status
            self.term_signal = term_signal
            proc.close(handle_close_cb)

        def timer_cb(timer):
            timer.close(handle_close_cb)
            proc.kill(15)

        loop = pyuv.Loop.default_loop()
        timer = pyuv.Timer(loop)
        timer.start(timer_cb, 0.1, 0)
        proc = pyuv.Process(loop)
        proc.spawn(file=sys.executable,
                   args=["proc_infinite.py"],
                   exit_callback=proc_exit_cb)
        loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 2)
        if sys.platform == 'win32':
            self.assertEqual(self.exit_status, 1)
        else:
            self.assertEqual(self.exit_status, 0)
        self.assertEqual(self.term_signal, 15)
예제 #2
0
    def test_process_cwd(self):
        self.exit_cb_called = 0
        self.close_cb_called = 0

        def proc_close_cb(proc):
            self.close_cb_called += 1

        def proc_exit_cb(proc, exit_status, term_signal):
            self.assertEqual(exit_status, 0)
            self.exit_cb_called += 1
            proc.close(proc_close_cb)

        loop = pyuv.Loop.default_loop()
        proc = pyuv.Process(loop)
        if sys.platform == 'win32':
            proc.spawn(file="cmd.exe",
                       args=["/c", "proc_basic.py"],
                       exit_callback=proc_exit_cb,
                       cwd=".")
        else:
            proc.spawn(file="./proc_basic.py",
                       exit_callback=proc_exit_cb,
                       cwd=".")
        loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 1)
예제 #3
0
    def test_process_uid_gid(self):
        self.exit_cb_called = 0
        self.close_cb_called = 0

        def proc_close_cb(proc):
            self.close_cb_called += 1

        def proc_exit_cb(proc, exit_status, term_signal):
            self.assertEqual(exit_status, 0)
            self.exit_cb_called += 1
            proc.close(proc_close_cb)

        if os.getuid() != 0:
            self.skipTest("test disabled if running as non-root")
            return
        p_info = pwd.getpwnam("nobody")
        loop = pyuv.Loop.default_loop()
        proc = pyuv.Process(loop)
        proc.spawn(file="./proc_basic.py",
                   exit_callback=proc_exit_cb,
                   uid=p_info.pw_uid,
                   gid=p_info.pw_gid,
                   flags=pyuv.UV_PROCESS_SETUID | pyuv.UV_PROCESS_SETGID)
        pid = proc.pid
        loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 1)
        self.assertNotEqual(pid, None)
예제 #4
0
    def spawn(self):
        """ spawn the process """
        kwargs = dict(file=self.cmd,
                      exit_callback=self._exit_cb,
                      args=self.args,
                      env=self.env,
                      cwd=self.cwd,
                      stdio=self._stdio)

        flags = 0
        if self.uid is not None:
            kwargs['uid'] = self.uid
            flags = pyuv.UV_PROCESS_SETUID

        if self.gid is not None:
            kwargs['gid'] = self.gid
            flags = flags | pyuv.UV_PROCESS_SETGID

        #if self.detach:
        if self.detach:
            flags = flags | pyuv.UV_PROCESS_DETACHED

        self.running = True
        self._process = pyuv.Process(self.loop)

        # spawn the process
        self._process.spawn(**kwargs)
        self._running = True

        # start redirecting IO
        self._redirect_io.start()

        if self._redirect_in is not None:
            self._redirect_in.start()
예제 #5
0
    def test_process_args(self):
        self.exit_cb_called = 0
        self.close_cb_called = 0
        self.received_output = None

        def handle_close_cb(handle):
            self.close_cb_called += 1

        def proc_exit_cb(proc, exit_status, term_signal):
            self.assertEqual(exit_status, 0)
            self.exit_cb_called += 1
            proc.close(handle_close_cb)

        def stdout_read_cb(handle, data, error):
            self.received_output = data.strip()
            handle.close(handle_close_cb)

        loop = pyuv.Loop.default_loop()
        stdout_pipe = pyuv.Pipe(loop)
        proc = pyuv.Process(loop)
        if sys.platform == 'win32':
            proc.spawn(file="cmd.exe",
                       args=[b"/c", b"proc_args_stdout.py", b"TEST"],
                       exit_callback=proc_exit_cb,
                       stdout=stdout_pipe)
        else:
            proc.spawn(file="./proc_args_stdout.py",
                       args=[b"TEST"],
                       exit_callback=proc_exit_cb,
                       stdout=stdout_pipe)
        stdout_pipe.start_read(stdout_read_cb)
        loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 2)
        self.assertEqual(self.received_output, b"TEST")
예제 #6
0
    def test_process_args(self):
        self.exit_cb_called = 0
        self.close_cb_called = 0
        self.received_output = None

        def handle_close_cb(handle):
            self.close_cb_called += 1

        def proc_exit_cb(proc, exit_status, term_signal):
            self.assertEqual(exit_status, 0)
            self.exit_cb_called += 1
            proc.close(handle_close_cb)

        def stdout_read_cb(handle, data, error):
            self.received_output = data.strip()
            handle.close(handle_close_cb)

        loop = pyuv.Loop.default_loop()
        stdout_pipe = pyuv.Pipe(loop)
        stdio = []
        stdio.append(pyuv.StdIO(flags=pyuv.UV_IGNORE))
        stdio.append(
            pyuv.StdIO(stream=stdout_pipe,
                       flags=pyuv.UV_CREATE_PIPE | pyuv.UV_WRITABLE_PIPE))
        proc = pyuv.Process(loop)
        proc.spawn(file=sys.executable,
                   args=["proc_args_stdout.py", "TEST"],
                   exit_callback=proc_exit_cb,
                   stdio=stdio)
        stdout_pipe.start_read(stdout_read_cb)
        loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 2)
        self.assertEqual(self.received_output, b"TEST")
예제 #7
0
    def spawn_process(self):
        args = sys.argv[1:]
        self.proc = pyuv.Process(self.loop)

        stdout_pipe = pyuv.Pipe(self.loop)
        stderr_pipe = pyuv.Pipe(self.loop)

        stdio = []
        stdio.append(pyuv.StdIO(flags=pyuv.UV_IGNORE))
        stdio.append(
            pyuv.StdIO(stream=stdout_pipe,
                       flags=pyuv.UV_CREATE_PIPE | pyuv.UV_WRITABLE_PIPE))
        stdio.append(
            pyuv.StdIO(stream=stderr_pipe,
                       flags=pyuv.UV_CREATE_PIPE | pyuv.UV_WRITABLE_PIPE))

        self.state = "RUNNING"

        self.proc.spawn(file=args[0],
                        args=args[1:],
                        cwd=os.getcwd(),
                        exit_callback=self.proc_exit_cb,
                        stdio=stdio)

        stdout_pipe.start_read(self.stdout_read_cb)
        stderr_pipe.start_read(self.stderr_read_cb)
예제 #8
0
파일: test_ipc.py 프로젝트: poupas/pyuv
 def _do_test(self):
     self.channel = pyuv.Pipe(self.loop, True)
     stdio = [pyuv.StdIO(stream=self.channel, flags=pyuv.UV_CREATE_PIPE|pyuv.UV_READABLE_PIPE|pyuv.UV_WRITABLE_PIPE)]
     proc = pyuv.Process(self.loop)
     proc.spawn(file=sys.executable, args=["proc_ipc_echo.py"], exit_callback=self.proc_exit_cb, stdio=stdio)
     self.channel.write2(b".", self.send_handle)
     self.channel.start_read2(partial(self.on_channel_read, self.send_handle_type))
     self.loop.run()
예제 #9
0
def freq1_cb(timer):
    global task2
    try:
        task2.close()
    except:
        pass
    task2 = pyuv.Process(loop)
    task2_spawn()
예제 #10
0
파일: test_ipc.py 프로젝트: poupas/pyuv
 def _do_test(self, test_type):
     self.connections = []
     self.local_conn_accepted = False
     self.tcp_server = None
     self.channel = pyuv.Pipe(self.loop, True)
     stdio = [pyuv.StdIO(stream=self.channel, flags=pyuv.UV_CREATE_PIPE|pyuv.UV_READABLE_PIPE|pyuv.UV_WRITABLE_PIPE)]
     proc = pyuv.Process(self.loop)
     proc.spawn(file=sys.executable, args=["proc_ipc.py", test_type, str(TEST_PORT)], exit_callback=self.proc_exit_cb, stdio=stdio)
     self.channel.start_read2(self.on_channel_read)
     self.loop.run()
예제 #11
0
def Memmcached_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global Memmcached
    print u'Memmcached exit'
    if common_callback("Memmcached") == 0:
        Memmcached.close()
        return
    Memmcached.close(handle_close_cb)
    Memmcached = pyuv.Process(loop)
    Memmcached_spawn()
    save_pid()
예제 #12
0
def Redis_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global Redis
    print u'Redis exit'
    if common_callback("Redis") == 0:
        Redis.close()
        return
    Redis.close(handle_close_cb)
    Redis = pyuv.Process(loop)
    Redis_spawn()
    save_pid()
예제 #13
0
파일: test_ipc.py 프로젝트: romuald/pyuv
 def test_ipc2(self):
     self.connections = []
     self.local_conn_accepted = False
     self.tcp_server = None
     self.channel = pyuv.Pipe(self.loop, True)
     stdio = [pyuv.StdIO(stream=self.channel, flags=pyuv.UV_CREATE_PIPE|pyuv.UV_READABLE_PIPE|pyuv.UV_WRITABLE_PIPE)]
     proc = pyuv.Process(self.loop)
     if sys.platform == 'win32':
         proc.spawn(file="cmd.exe", args=["/c", " proc_ipc.py", "listen_after_write"], exit_callback=self.proc_exit_cb, stdio=stdio)
     else:
         proc.spawn(file=sys.executable, args=["proc_ipc.py", "listen_after_write"], exit_callback=self.proc_exit_cb, stdio=stdio)
     self.channel.start_read2(self.on_channel_read)
     self.loop.run()
예제 #14
0
파일: test_ipc.py 프로젝트: romuald/pyuv
 def test_ipc_send_recv(self):
     # Handle that will be sent to the process and back
     self.send_pipe = pyuv.Pipe(self.loop, True)
     self.send_pipe.bind(TEST_PIPE)
     self.channel = pyuv.Pipe(self.loop, True)
     stdio = [pyuv.StdIO(stream=self.channel, flags=pyuv.UV_CREATE_PIPE|pyuv.UV_READABLE_PIPE|pyuv.UV_WRITABLE_PIPE)]
     proc = pyuv.Process(self.loop)
     if sys.platform == 'win32':
         proc.spawn(file="cmd.exe", args=["/c", " proc_ipc_echo.py"], exit_callback=self.proc_exit_cb, stdio=stdio)
     else:
         proc.spawn(file=sys.executable, args=["proc_ipc_echo.py"], exit_callback=self.proc_exit_cb, stdio=stdio)
     self.channel.write2(b".", self.send_pipe)
     self.channel.start_read2(self.on_channel_read)
     self.loop.run()
예제 #15
0
    def test_process_stdin(self):
        self.exit_cb_called = 0
        self.close_cb_called = 0
        self.received_output = None
        self.exit_status = -1
        self.term_signal = 0

        def handle_close_cb(handle):
            self.close_cb_called += 1

        def proc_exit_cb(proc, exit_status, term_signal):
            self.exit_cb_called += 1
            self.exit_status = exit_status
            self.term_signal = term_signal
            proc.close(handle_close_cb)

        def stdout_read_cb(handle, data, error):
            if data:
                self.received_output = data.strip()
            handle.close(handle_close_cb)

        def stdin_write_cb(handle, error):
            handle.close(handle_close_cb)

        loop = pyuv.Loop.default_loop()
        stdin_pipe = pyuv.Pipe(loop)
        stdout_pipe = pyuv.Pipe(loop)
        stdio = []
        stdio.append(
            pyuv.StdIO(stream=stdin_pipe,
                       flags=pyuv.UV_CREATE_PIPE | pyuv.UV_READABLE_PIPE))
        stdio.append(
            pyuv.StdIO(stream=stdout_pipe,
                       flags=pyuv.UV_CREATE_PIPE | pyuv.UV_WRITABLE_PIPE))
        proc = pyuv.Process(loop)
        if sys.platform == 'win32':
            proc.spawn(file="cmd.exe",
                       args=["/c", "proc_stdin_stdout.py"],
                       exit_callback=proc_exit_cb,
                       stdio=stdio)
        else:
            proc.spawn(file="./proc_stdin_stdout.py",
                       exit_callback=proc_exit_cb,
                       stdio=stdio)
        stdout_pipe.start_read(stdout_read_cb)
        stdin_pipe.write(b"TEST" + common.linesep, stdin_write_cb)
        loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 3)
        self.assertEqual(self.received_output, b"TEST")
예제 #16
0
    def spawn(self, once=False, graceful_timeout=None, env=None):
        """ spawn the process """

        self.once = once
        self.graceful_timeout = graceful_timeout

        if env is not None:
            self.env.update(env)

        kwargs = dict(file=self.cmd,
                      exit_callback=self._exit_cb,
                      args=self.args,
                      env=self.env,
                      cwd=self.cwd,
                      stdio=self._stdio)

        flags = 0
        if self.uid is not None:
            kwargs['uid'] = self.uid
            flags = pyuv.UV_PROCESS_SETUID

        if self.gid is not None:
            kwargs['gid'] = self.gid
            flags = flags | pyuv.UV_PROCESS_SETGID

        if self.detach:
            flags = flags | pyuv.UV_PROCESS_DETACHED

        self.running = True
        self._process = pyuv.Process(self.loop)

        # spawn the process
        self._process.spawn(**kwargs)
        self._running = True
        self._os_pid = self._process.pid
        self._pprocess = psutil.Process(self._process.pid)

        # start to cycle the cpu stats so we can have an accurate number on
        # the first call of ``Process.stats``
        self.loop.queue_work(self._init_cpustats)

        # start redirecting IO
        self._redirect_io.start()

        if self._redirect_in is not None:
            self._redirect_in.start()

        for stream in self.streams.values():
            stream.start()
예제 #17
0
파일: test_process.py 프로젝트: poupas/pyuv
    def test_process_detached(self):
        self.exit_cb_called = 0

        def proc_exit_cb(proc, exit_status, term_signal):
            self.exit_cb_called += 1

        proc = pyuv.Process(self.loop)
        proc.spawn(file=sys.executable,
                   args=["proc_basic.py"],
                   exit_callback=proc_exit_cb,
                   flags=pyuv.UV_PROCESS_DETACHED)
        proc.ref = False
        pid = proc.pid
        self.loop.run()
        self.assertEqual(self.exit_cb_called, 0)
        proc.kill(0)
        proc.kill(15)
        self.assertNotEqual(pid, None)
예제 #18
0
def RedisSelf_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global RedisSelf
    global RedisSelf_pipe
    global RedisSelf_error_pipe
    print u'RedisSelf exit'
    if common_callback("RedisSelf") == 0:
        RedisSelf.close()
        return
    RedisSelf_log.write(log_t('RedisSelf', proc.pid, 'exit'))
    RedisSelf_log.write(log_t('RedisSelf', proc.pid, 'auto start'))
    RedisSelf_log.flush()
    RedisSelf.close(handle_close_cb)
    RedisSelf = pyuv.Process(loop)
    RedisSelf_pipe = pyuv.Pipe(loop)
    RedisSelf_error_pipe = pyuv.Pipe(loop)
    RedisSelf_spawn()
    save_pid()
예제 #19
0
def DataCommCenter_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global DataCommCenter
    global DataCommCenter_pipe
    global DataCommCenter_error_pipe
    print u'DataCommCenter exit'
    if common_callback("DataCommCenter") == 0:
        DataCommCenter.close()
        return
    DataCommCenter_log.write(log_t('DataCommCenter', proc.pid, 'exit'))
    DataCommCenter_log.write(log_t('DataCommCenter', proc.pid, 'auto start'))
    DataCommCenter_log.flush()
    DataCommCenter.close(handle_close_cb)
    DataCommCenter = pyuv.Process(loop)
    DataCommCenter_pipe = pyuv.Pipe(loop)
    DataCommCenter_error_pipe = pyuv.Pipe(loop)
    DataCommCenter_spawn()
    save_pid()
예제 #20
0
def ZkposAdms_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global ZkposAdms
    global ZkposAdms_pipe
    global ZkposAdms_error_pipe
    print u'ZkposAdms exit'
    if common_callback("ZkposAdms") == 0:
        ZkposAdms.close()
        return
    ZkposAdms_log.write(log_t('ZkposAdms', proc.pid, 'exit'))
    ZkposAdms_log.write(log_t('ZkposAdms', proc.pid, 'auto start'))
    ZkposAdms_log.flush()
    ZkposAdms.close(handle_close_cb)
    ZkposAdms = pyuv.Process(loop)
    ZkposAdms_pipe = pyuv.Pipe(loop)
    ZkposAdms_error_pipe = pyuv.Pipe(loop)
    ZkposAdms_spawn()
    save_pid()
예제 #21
0
def InstantMsg_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global InstantMsg
    global InstantMsg_pipe
    global InstantMsg_error_pipe
    print u'InstantMsg exit'
    if common_callback("InstantMsg") == 0:
        InstantMsg.close()
        return
    InstantMsg_log.write(log_t('InstantMsg', proc.pid, 'exit'))
    InstantMsg_log.write(log_t('InstantMsg', proc.pid, 'auto start'))
    InstantMsg_log.flush()
    InstantMsg.close(handle_close_cb)
    InstantMsg = pyuv.Process(loop)
    InstantMsg_pipe = pyuv.Pipe(loop)
    InstantMsg_error_pipe = pyuv.Pipe(loop)
    InstantMsg_spawn()
    save_pid()
예제 #22
0
def FTPSync_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global FTPSync
    global FTPSync_pipe
    global FTPSync_error_pipe
    print u'FTPSync exit'
    if common_callback("FTPSync") == 0:
        FTPSync.close()
        return
    FTPSync_log.write(log_t('FTPSync', proc.pid, 'exit'))
    FTPSync_log.write(log_t('FTPSync', proc.pid, 'auto start'))
    FTPSync_log.flush()
    FTPSync.close(handle_close_cb)
    FTPSync = pyuv.Process(loop)
    FTPSync_pipe = pyuv.Pipe(loop)
    FTPSync_error_pipe = pyuv.Pipe(loop)
    FTPSync_spawn()
    save_pid()
예제 #23
0
def AutoCalculate_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global AutoCalculate
    global AutoCalculate_pipe
    global AutoCalculate_error_pipe
    print u'AutoCalculate exit'
    if common_callback("AutoCalculate") == 0:
        AutoCalculate.close()
        return
    AutoCalculate_log.write(log_t('AutoCalculate', proc.pid, 'exit'))
    AutoCalculate_log.write(log_t('AutoCalculate', proc.pid, 'auto start'))
    AutoCalculate_log.flush()
    AutoCalculate.close(handle_close_cb)
    AutoCalculate = pyuv.Process(loop)
    AutoCalculate_pipe = pyuv.Pipe(loop)
    AutoCalculate_error_pipe = pyuv.Pipe(loop)
    AutoCalculate_spawn()
    save_pid()
예제 #24
0
def WriteData_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global WriteData
    global WriteData_pipe
    global WriteData_error_pipe
    print u'WriteData exit'
    if common_callback("WriteData") == 0:
        WriteData.close()
        return
    WriteData_log.write(log_t('WriteData', proc.pid, 'exit'))
    WriteData_log.write(log_t('WriteData', proc.pid, 'auto start'))
    WriteData_log.flush()
    WriteData.close(handle_close_cb)
    WriteData = pyuv.Process(loop)
    WriteData_pipe = pyuv.Pipe(loop)
    WriteData_error_pipe = pyuv.Pipe(loop)
    WriteData_spawn()
    save_pid()
예제 #25
0
def webserver_exit_cb(proc, exit_status, term_signal):
    exit_status == 0
    global webserver
    global webserver_pipe
    global webserver_error_pipe
    print u'webserver exit'
    if common_callback("webserver") == 0:
        webserver.close()
        return
    webserver_log.write(log_t('webserver', proc.pid, 'exit'))
    webserver_log.write(log_t('webserver', proc.pid, 'auto start'))
    webserver_log.flush()
    webserver.close(handle_close_cb)
    webserver = pyuv.Process(loop)
    webserver_pipe = pyuv.Pipe(loop)
    webserver_error_pipe = pyuv.Pipe(loop)
    webserver_spawn()
    save_pid()
예제 #26
0
파일: test_process.py 프로젝트: poupas/pyuv
    def test_process_cwd(self):
        self.exit_cb_called = 0
        self.close_cb_called = 0

        def proc_close_cb(proc):
            self.close_cb_called += 1

        def proc_exit_cb(proc, exit_status, term_signal):
            self.assertEqual(exit_status, 0)
            self.exit_cb_called += 1
            proc.close(proc_close_cb)

        proc = pyuv.Process(self.loop)
        proc.spawn(file=sys.executable,
                   args=["proc_basic.py"],
                   exit_callback=proc_exit_cb,
                   cwd=".")
        self.loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 1)
예제 #27
0
 def test_ipc2(self):
     self.connections = []
     self.local_conn_accepted = False
     self.tcp_server = None
     self.channel = pyuv.Pipe(self.loop, True)
     proc = pyuv.Process(self.loop)
     if sys.platform == 'win32':
         proc.spawn(file="cmd.exe",
                    args=[
                        b"/c", EXECUTABLE + b" proc_ipc.py",
                        b"listen_after_write"
                    ],
                    exit_callback=self.proc_exit_cb,
                    stdin=self.channel)
     else:
         proc.spawn(file=sys.executable,
                    args=[b"proc_ipc.py", b"listen_after_write"],
                    exit_callback=self.proc_exit_cb,
                    stdin=self.channel)
     self.channel.start_read2(self.on_channel_read)
     self.loop.run()
예제 #28
0
 def _connect_child(self, argv):
     self._write_stream = pyuv.Pipe(self._loop)
     self._read_stream = pyuv.Pipe(self._loop)
     self._error_stream = pyuv.Pipe(self._loop)
     stdin = pyuv.StdIO(self._write_stream,
                        flags=pyuv.UV_CREATE_PIPE + pyuv.UV_READABLE_PIPE)
     stdout = pyuv.StdIO(self._read_stream,
                         flags=pyuv.UV_CREATE_PIPE + pyuv.UV_WRITABLE_PIPE)
     stderr = pyuv.StdIO(self._error_stream,
                         flags=pyuv.UV_CREATE_PIPE + pyuv.UV_WRITABLE_PIPE)
     self._process = pyuv.Process(self._loop)
     self._process.spawn(file=argv[0],
                         exit_callback=self._on_exit,
                         args=argv[1:],
                         flags=pyuv.UV_PROCESS_WINDOWS_HIDE,
                         stdio=(
                             stdin,
                             stdout,
                             stderr,
                         ))
     self._error_stream.start_read(self._on_read)
예제 #29
0
    def test_process_basic(self):
        self.exit_cb_called = 0
        self.close_cb_called = 0

        def proc_close_cb(proc):
            self.close_cb_called += 1

        def proc_exit_cb(proc, exit_status, term_signal):
            self.assertEqual(exit_status, 0)
            self.exit_cb_called += 1
            proc.close(proc_close_cb)

        loop = pyuv.Loop.default_loop()
        proc = pyuv.Process(loop)
        proc.spawn(file=sys.executable,
                   args=["proc_basic.py"],
                   exit_callback=proc_exit_cb)
        pid = proc.pid
        loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 1)
        self.assertNotEqual(pid, None)
예제 #30
0
파일: test_process.py 프로젝트: poupas/pyuv
    def test_process_uid_fail(self):
        self.exit_cb_called = 0
        self.close_cb_called = 0

        def proc_close_cb(proc):
            self.close_cb_called += 1

        def proc_exit_cb(proc, exit_status, term_signal):
            self.assertNotEqual(exit_status, 0)
            self.exit_cb_called += 1
            proc.close(proc_close_cb)

        if os.getuid() != 0:
            self.skipTest("test disabled if running as non-root")
            return
        proc = pyuv.Process(self.loop)
        proc.spawn(file="./proc_basic.py",
                   exit_callback=proc_exit_cb,
                   uid=-42424242,
                   flags=pyuv.UV_PROCESS_SETUID)
        self.loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 1)