Exemple #1
0
 def test_ipc_attr(self):
     handle = pyuv.Pipe(self.loop)
     self.check_ipc(handle, False)
     handle = pyuv.Pipe(self.loop, False)
     self.check_ipc(handle, False)
     handle = pyuv.Pipe(self.loop, True)
     self.check_ipc(handle, True)
Exemple #2
0
 def __init__(self, address=None, port=None):
     self._loop = pyuv.Loop()
     self._error = None
     self._data = None
     self._written = True
     self._connected = False
     self._timed_out = False
     self._timer = pyuv.Timer(self._loop)
     self._timeout_cb = self._on_timeout.__get__(self, UvStream)
     self._read_cb = self._on_read.__get__(self, UvStream)
     self._write_cb = self._on_write.__get__(self, UvStream)
     connect_cb = self._on_connect.__get__(self, UvStream)
     # Select the type of handle
     if port:
         # tcp
         self._stream = pyuv.TCP(self._loop)
         self._stream.connect((address, port), connect_cb)
     elif address:
         # named pipe or unix socket
         self._stream = pyuv.Pipe(self._loop)
         self._stream.connect(address, connect_cb)
     else:
         # stdin/stdout
         self._read_stream = pyuv.Pipe(self._loop) 
         self._read_stream.open(sys.stdin.fileno())
         self._write_stream = pyuv.Pipe(self._loop) 
         self._write_stream.open(sys.stdout.fileno())
Exemple #3
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)
Exemple #4
0
 def test_pipe_null(self):
     self.server = pyuv.Pipe(self.loop)
     self.server.pending_instances(100)
     self.server.bind(TEST_PIPE)
     self.server.listen(self.on_connection)
     self.client = pyuv.Pipe(self.loop)
     self.client.connect(TEST_PIPE, self.on_client_connection)
     self.loop.run()
Exemple #5
0
 def test_fileno(self):
     server = pyuv.Pipe(self.loop)
     server.bind(TEST_PIPE)
     self.check_fileno(server)
     server.listen(self.on_connection)
     client = pyuv.Pipe(self.loop)
     client.connect(TEST_PIPE, self.on_client_connection)
     self.check_fileno(client)
     self.loop.run()
Exemple #6
0
 def test_pipe1_abstract(self):
     self.server = pyuv.Pipe(self.loop)
     self.pipe_name = ABSTRACT_PIPE
     self.server.bind(self.pipe_name)
     self.assertEqual(self.server.getsockname(), self.pipe_name)
     self.server.listen(self.on_connection)
     self.client = pyuv.Pipe(self.loop)
     self.client.connect(self.pipe_name, self.on_client_connection)
     self.loop.run()
Exemple #7
0
 def test_pipe1(self):
     self.server = pyuv.Pipe(self.loop)
     self.server.pending_instances(100)
     self.pipe_name = TEST_PIPE
     self.server.bind(self.pipe_name)
     self.assertEqual(self.server.getsockname(), self.pipe_name)
     self.server.listen(self.on_connection)
     self.client = pyuv.Pipe(self.loop)
     self.client.connect(self.pipe_name, self.on_client_connection)
     self.loop.run()
Exemple #8
0
 def test_pipe1(self):
     self.shutdown_cb_called = 0
     self.close_cb_called = 0
     self.server = pyuv.Pipe(self.loop)
     self.server.bind(TEST_PIPE)
     self.server.listen(self.on_connection)
     self.client = pyuv.Pipe(self.loop)
     self.client.connect(TEST_PIPE, self.on_client_connection)
     self.loop.run()
     self.assertEqual(self.shutdown_cb_called, 1)
     self.assertEqual(self.close_cb_called, 3)
Exemple #9
0
    def _start_process_async(self, async_handle):
        # check config
        if self._proc_config == None:
            raise TypeError

        mc_w_config = self._proc_config
        # set args
        cmd_args = [
            mc_w_config.java_bin,
            "-Xms%sM" % int(mc_w_config.min_RAM),
            "-Xmx%sM" % int(mc_w_config.max_RAM), "-jar", mc_w_config.jar_file,
            "nogui"
        ]

        self._init_env(mc_w_config.proc_cwd, mc_w_config.port,
                       mc_w_config.max_player)
        logger.debug("cmd args: %s" % cmd_args)

        # init pipes
        self._stdin_pipe = pyuv.Pipe(self._loop, True)
        self._stdout_pipe = pyuv.Pipe(self._loop, True)
        self._stderr_pipe = pyuv.Pipe(self._loop, True)

        # set pipes
        stdin = pyuv.StdIO(stream=self._stdin_pipe,
                           flags=pyuv.UV_CREATE_PIPE | pyuv.UV_READABLE_PIPE)
        stdout = pyuv.StdIO(stream=self._stdout_pipe,
                            flags=pyuv.UV_CREATE_PIPE | pyuv.UV_WRITABLE_PIPE)
        stderr = pyuv.StdIO(stream=self._stderr_pipe,
                            flags=pyuv.UV_CREATE_PIPE | pyuv.UV_WRITABLE_PIPE)

        # spawn process
        self._proc = pyuv.Process.spawn(self._loop,
                                        args=cmd_args,
                                        exit_callback=self.on_exit,
                                        stdio=[stdin, stdout, stderr],
                                        cwd=mc_w_config.proc_cwd,
                                        flags=pyuv.UV_PROCESS_DETACHED)
        # set pid
        self._pid = self._proc.pid
        logger.info("Start Process pid=(%s)" % self._pid)

        # on read
        self._stdout_pipe.start_read(self.on_stdout_read)
        self._stderr_pipe.start_read(self.on_stderr_read)

        # incr active count, reset crash count, run callbacks and so on
        self._proc_pool.incr_active_count()
        logger.debug("active count = %s" % self._proc_pool.get_active_count())

        # run callback
        self.on_instance_start(self.inst_id)
        return True
Exemple #10
0
 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()
Exemple #11
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")
Exemple #12
0
    def __init__(self, loop, process, stdio=[]):
        self.loop = loop
        self.process = process
        self._emitter = EventEmitter(loop)

        self._stdio = []
        self._channels = []

        if not stdio:
            self._stdio = [
                pyuv.StdIO(flags=pyuv.UV_IGNORE),
                pyuv.StdIO(flags=pyuv.UV_IGNORE)
            ]

        else:
            # create (channel, stdio) pairs
            for label in stdio[:2]:
                # io registered can any label, so it's easy to redirect
                # stderr to stdout, just use the same label.
                p = pyuv.Pipe(loop)
                io = pyuv.StdIO(stream=p, flags=pyuv.UV_CREATE_PIPE | \
                                                pyuv.UV_READABLE_PIPE | \
                                                pyuv.UV_WRITABLE_PIPE)
                setattr(p, 'label', label)
                self._channels.append(p)
                self._stdio.append(io)
Exemple #13
0
 def on_channel_read(self, handle, data, pending, error):
     self.assertEqual(pending, pyuv.UV_NAMED_PIPE)
     self.recv_pipe = pyuv.Pipe(self.loop)
     self.channel.accept(self.recv_pipe)
     self.channel.close()
     self.send_pipe.close()
     self.recv_pipe.close()
Exemple #14
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)
     pyuv.Process.spawn(self._loop,
                        args=argv,
                        exit_callback=self._on_exit,
                        flags=pyuv.UV_PROCESS_WINDOWS_HIDE,
                        stdio=(stdin, stdout, stderr,))
     self._error_stream.start_read(self._on_read)
Exemple #15
0
 def test_pipe_set_blocking(self):
     pipe = pyuv.Pipe(self.loop)
     pipe.bind(TEST_PIPE)
     pipe.set_blocking(True)
     pipe.set_blocking(False)
     pipe.close()
     self.loop.run()
Exemple #16
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")
Exemple #17
0
    def test_process_env(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)

        stdout_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))
        proc = pyuv.Process.spawn(self.loop,
                                  args=[sys.executable, "proc_env_stdout.py"],
                                  env={"TEST": "TEST"},
                                  exit_callback=proc_exit_cb,
                                  stdio=stdio)
        stdout_pipe.start_read(stdout_read_cb)
        self.loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 2)
        self.assertEqual(self.received_output, b"TEST")
Exemple #18
0
    def _on_connection(self, handle, error):
        if error:
            logging.error('_on_connection: {}'.format(error))
            return

        if type(self.socket) == pyuv.TCP:
            client = pyuv.TCP(self.loop)
        else:
            client = pyuv.Pipe(self.loop, True)

        self.socket.accept(client)

        if self.forward_address:
            self.on_connection(client)
        else:
            context = {
                'buffer': [],
                'stage': 0,
                'header': b'',
            }

            client.start_read(
                lambda handle, data, error: self._socks5_read(
                    handle, data, error, context
                ))
Exemple #19
0
 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()
Exemple #20
0
 def on_connection(self, server, error):
     self.assertEqual(error, None)
     self.check_fileno(server)
     client = pyuv.Pipe(self.loop)
     server.accept(client)
     self.check_fileno(client)
     client.close()
     server.close()
Exemple #21
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()
Exemple #22
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()
Exemple #23
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()
Exemple #24
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()
Exemple #25
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()
Exemple #26
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()
Exemple #27
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()
Exemple #28
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()
Exemple #29
0
 def __init__(self, loop, process):
     self.loop = loop
     self.process = process
     self.channel = pyuv.Pipe(loop)
     self.stdio = pyuv.StdIO(stream=self.channel,
             flags=pyuv.UV_CREATE_PIPE | \
                     pyuv.UV_READABLE_PIPE | \
                     pyuv.UV_WRITABLE_PIPE )
     self._emitter = EventEmitter(loop)
Exemple #30
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)

        stdin_pipe = pyuv.Pipe(self.loop)
        stdout_pipe = pyuv.Pipe(self.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.spawn(
            self.loop,
            args=[sys.executable, "proc_stdin_stdout.py"],
            exit_callback=proc_exit_cb,
            stdio=stdio)
        stdout_pipe.start_read(stdout_read_cb)
        stdin_pipe.write(b"TEST" + linesep, stdin_write_cb)
        self.loop.run()
        self.assertEqual(self.exit_cb_called, 1)
        self.assertEqual(self.close_cb_called, 3)
        self.assertEqual(self.received_output, b"TEST")