def receivedata(timeout):
     try:
         res = Communication.channel.receive(timeout)
         if type(res) is bytes:
             res = execnet.loads(res)
         Communication.log("data: " + str(res))
         return res
     except Communication.channel.TimeoutError as e:
         pass
     return None
Beispiel #2
0
 def get(self, default=_nodefault):
     try:
         data = self.keyfs._get(self.relpath)
     except KeyError:
         if default == _nodefault:
             return self.type()
         return default
     if self.type == bytes:
         return data
     val = loads(data)
     assert isinstance(val, self.type), val
     return val
Beispiel #3
0
 def get(self, default=_nodefault):
     try:
         data = self.keyfs._get(self.relpath)
     except KeyError:
         if default == _nodefault:
             return self.type()
         return default
     if self.type == bytes:
         return data
     val = loads(data)
     assert isinstance(val, self.type), val
     return val
    def handlemessage(message, globalvalues):
        try:
            l, g = locals().copy(), globals().copy()
            for key, value in globalvalues.items():
                g[key] = value
            res = execnet.loads(message)

            if type(res) is not tuple:
                Communication.log("message is not a tuple:" + str(res))
                return None
            if len(res) <= 1:
                return None

            if res[0] == "value":
                Communication.log("value:" + res[1])
                return res[1]
            else:
                Communication.log("cmd:\n" + res[1])
                exec(res[1], g, l)
                return None
        except Exception as e:
            Communication.exception(e)
Beispiel #5
0
    def get(self, key, default):
        """ return cached value for the given key.  If no value
        was yet cached or the value cannot be read, the specified
        default is returned.

        :param key: must be a ``/`` separated value. Usually the first
             name is the name of your plugin or your application.
        :param default: must be provided in case of a cache-miss or
             invalid cache values.

        """
        from execnet import loads, DataFormatError
        path = self._getvaluepath(key)
        if path.check():
            f = path.open("rb")
            try:
                try:
                    return loads(f.read())
                finally:
                    f.close()
            except DataFormatError:
                self.trace("cache-invalid at %s" % (key,))
        return default
Beispiel #6
0
    def get(self, key, default):
        """ return cached value for the given key.  If no value
        was yet cached or the value cannot be read, the specified
        default is returned.

        :param key: must be a ``/`` separated value. Usually the first
             name is the name of your plugin or your application.
        :param default: must be provided in case of a cache-miss or
             invalid cache values.

        """
        from execnet import loads, DataFormatError
        path = self._getvaluepath(key)
        if path.check():
            f = path.open("rb")
            try:
                try:
                    return loads(f.read())
                finally:
                    f.close()
            except DataFormatError:
                self.trace("cache-invalid at %s" % (key, ))
        return default
Beispiel #7
0
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))
Beispiel #8
0
 def test_serializer_api(self, val):
     dumped = execnet.dumps(val)
     val2 = execnet.loads(dumped)
     assert val == val2
Beispiel #9
0
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))
Beispiel #10
0
 def test_serializer_api(self, val):
     dumped = execnet.dumps(val)
     val2 = execnet.loads(dumped)
     assert val == val2