How to use the execnet.gateway_base function in execnet

To help you get started, we’ve selected a few execnet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytest-dev / execnet / execnet / gateway.py View on Github external
source = inspect.getsource(source)
        elif isinstance(source, types.FunctionType):
            call_name = source.__name__
            file_name = inspect.getsourcefile(source)
            source = _source_of_function(source)
        else:
            source = textwrap.dedent(str(source))

        if not call_name and kwargs:
            raise TypeError("can't pass kwargs to non-function remote_exec")

        channel = self.newchannel()
        self._send(
            Message.CHANNEL_EXEC,
            channel.id,
            gateway_base.dumps_internal((source, file_name, call_name, kwargs)),
        )
        return channel
github pytest-dev / execnet / testing / test_gateway.py View on Github external
def test_no_tracing_by_default(self):
        assert gateway_base.trace == gateway_base.notrace, \
                "trace does not to default to empty tracing"
github pytest-dev / execnet / execnet / gateway_bootstrap.py View on Github external
def bootstrap_socket(io, id):
    # XXX: switch to spec
    from execnet.gateway_socket import SocketIO

    sendexec(
        io,
        inspect.getsource(gateway_base),
        "import socket",
        inspect.getsource(SocketIO),
        "try: execmodel",
        "except NameError:",
        "   execmodel = get_execmodel('thread')",
        "io = SocketIO(clientsock, execmodel)",
        "io.write('1'.encode('ascii'))",
        "serve(io, id='%s-worker')" % id,
    )
    s = io.read(1)
    assert s == "1".encode("ascii")
github pytest-dev / execnet / testing / test_gateway.py View on Github external
def run_me(channel=None):
                raise ValueError('me')

            if __name__ == '__channelexec__':
                run_me()
            """
            )
        )

        monkeypatch.syspath_prepend(tmpdir)
        import remotetest

        ch = gw.remote_exec(remotetest)
        try:
            ch.receive()
        except execnet.gateway_base.RemoteError as e:
            assert 'remotetest.py", line 3, in run_me' in str(e)
            assert "ValueError: me" in str(e)
        finally:
            ch.close()

        ch = gw.remote_exec(remotetest.run_me)
        try:
            ch.receive()
        except execnet.gateway_base.RemoteError as e:
            assert 'remotetest.py", line 3, in run_me' in str(e)
            assert "ValueError: me" in str(e)
        finally:
            ch.close()
github pytest-dev / execnet / testing / test_compatibility_regressions.py View on Github external
def test_opcodes():
    data = vars(gateway_base.opcode)
    computed = {k: v for k, v in data.items() if "__" not in k}
    assert computed == {
        "BUILDTUPLE": "@".encode("ascii"),
        "BYTES": "A".encode("ascii"),
        "CHANNEL": "B".encode("ascii"),
        "FALSE": "C".encode("ascii"),
        "FLOAT": "D".encode("ascii"),
        "FROZENSET": "E".encode("ascii"),
        "INT": "F".encode("ascii"),
        "LONG": "G".encode("ascii"),
        "LONGINT": "H".encode("ascii"),
        "LONGLONG": "I".encode("ascii"),
        "NEWDICT": "J".encode("ascii"),
        "NEWLIST": "K".encode("ascii"),
        "NONE": "L".encode("ascii"),
        "PY2STRING": "M".encode("ascii"),
github pytest-dev / execnet / testing / test_gateway.py View on Github external
def test_no_tracing_by_default(self):
        assert (
            gateway_base.trace == gateway_base.notrace
        ), "trace does not to default to empty tracing"
github pytest-dev / execnet / testing / test_gateway.py View on Github external
def test_remoteerror_readable_traceback(self, gw):
        e = py.test.raises(gateway_base.RemoteError,
            'gw.remote_exec("x y").waitclose()')
        assert "gateway_base" in e.value.formatted
github pytest-dev / execnet / testing / test_basics.py View on Github external
def test_serializer_api_version_error(monkeypatch):
    bchr = gateway_base.bchr
    monkeypatch.setattr(gateway_base, "DUMPFORMAT_VERSION", bchr(1))
    dumped = execnet.dumps(42)
    monkeypatch.setattr(gateway_base, "DUMPFORMAT_VERSION", bchr(2))
    pytest.raises(execnet.DataFormatError, lambda: execnet.loads(dumped))
github alfredodeza / remoto / remoto / lib / execnet / gateway.py View on Github external
if isinstance(source, types.ModuleType):
            linecache.updatecache(inspect.getsourcefile(source))
            source = inspect.getsource(source)
        elif isinstance(source, types.FunctionType):
            call_name = source.__name__
            source = _source_of_function(source)
        else:
            source = textwrap.dedent(str(source))

        if call_name is None and kwargs:
            raise TypeError("can't pass kwargs to non-function remote_exec")

        channel = self.newchannel()
        self._send(Message.CHANNEL_EXEC,
                   channel.id,
                   gateway_base.dumps_internal((source, call_name, kwargs)))
        return channel