Beispiel #1
0
    def call_instance_method_thread(self, request):
        """ Call a method on an instance *in a new thread*.

        Return the Id of a Future object which finishes when the method in
        thread finishes.

        """

        obj         = self._id_to_object_map[request['id']]
        method_name = request['method_name']
        args        = self._unmarshal_all(request['args'])
        method      = getattr(obj, method_name)

        from jigna.core.concurrent import Future
        future = Future(
            method, args=tuple(args), dispatch=self.trait_change_dispatch
        )

        def _on_done(result):
            event = dict(
                obj  = str(id(future)),
                name = 'done',
                data = result
            )
            self.send_event(event)

        def _on_error(error):
            error_msg = ''.join(traceback.format_exception(*error))

            logger.error(error_msg)

            event = dict(
                obj  = str(id(future)),
                name = 'error',
                data = error_msg
            )
            self.send_event(event)

        future.on_done(_on_done)
        future.on_error(_on_error)

        return self._marshal(id(future))
Beispiel #2
0
    def call_instance_method_thread(self, request):
        """ Call a method on an instance *in a new thread*.

        Return the Id of a Future object which finishes when the method in
        thread finishes.

        """

        obj = self._id_to_object_map[request['id']]
        method_name = request['method_name']
        args = self._unmarshal_all(request['args'])
        method = getattr(obj, method_name)

        from jigna.core.concurrent import Future
        future = Future(method,
                        args=tuple(args),
                        dispatch=self.trait_change_dispatch)

        def _on_done(result):
            event = dict(obj=str(id(future)), name='done', data=result)
            self.send_event(event)

        def _on_error(error):
            error_msg = ''.join(traceback.format_exception(*error))

            logger.error(error_msg)

            event = dict(obj=str(id(future)), name='error', data=error_msg)
            self.send_event(event)

        future.on_done(_on_done)
        future.on_error(_on_error)

        return self._marshal(id(future))
Beispiel #3
0
    def _handle_request_thread(self, request):
        """ Handle a jsonized request from a client and fire the method
        in a thread.
        """

        from jigna.core.concurrent import Future

        method = getattr(self, request['kind'])
        future = Future(method, args=(request, ),
                        dispatch=self.trait_change_dispatch)

        def _on_done(result):
            event = dict(
                obj  = str(id(future)),
                name = 'done',
                data = result
            )
            print "done, send_event:", event
            self.send_event(event)

        def _on_error(error):
            import traceback
            type, value, tb = error
            error_msg = '\n'.join(traceback.format_tb(tb))
            event = dict(
                obj  = str(id(future)),
                name = 'error',
                data = error_msg
            )
            print "error, send_event:", event
            self.send_event(event)

        future.on_done(_on_done)
        future.on_error(_on_error)

        return id(future)