You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/05/19 11:56:10 UTC

[GitHub] [arrow] lidavidm commented on pull request #10318: ARROW-12050: [C++][Python][FlightRPC] Make Flight operations interruptible in Python

lidavidm commented on pull request #10318:
URL: https://github.com/apache/arrow/pull/10318#issuecomment-844030751


   It solves a problem for Python users: if you Ctrl-C in something like read_all(), nothing will happen because control is in C++/Flight code, and then you're stuck waiting for the call to complete. 
   
   If you apply this diff to python/examples/flight/server.py:
   ```diff
   diff --git a/python/examples/flight/server.py b/python/examples/flight/server.py
   index 7a6b6697e..bc1df21d1 100644
   --- a/python/examples/flight/server.py
   +++ b/python/examples/flight/server.py
   @@ -73,6 +73,7 @@ class FlightServer(pyarrow.flight.FlightServerBase):
                yield self._make_flight_info(key, descriptor, table)
    
        def get_flight_info(self, context, descriptor):
   +        return self._make_flight_info("", descriptor, pyarrow.schema([]).empty_table())
            key = FlightServer.descriptor_to_key(descriptor)
            if key in self.flights:
                table = self.flights[key]
   @@ -86,10 +87,10 @@ class FlightServer(pyarrow.flight.FlightServerBase):
            print(self.flights[key])
    
        def do_get(self, context, ticket):
   -        key = ast.literal_eval(ticket.ticket.decode())
   -        if key not in self.flights:
   -            return None
   -        return pyarrow.flight.RecordBatchStream(self.flights[key])
   +        import itertools
   +        schema = pyarrow.schema([])
   +        rb = pyarrow.RecordBatch.from_arrays([], schema=schema)
   +        return pyarrow.flight.GeneratorStream(schema, itertools.repeat(rb))
    
        def list_actions(self, context):
            return [
   ```
   
   Then you can start the server:
   
   ```sh
   arrow/python$ env PYTHONPATH=$(pwd) python examples/flight/server.py --port 2000 &
   arrow/python$ env PYTHONPATH=(pwd) python examples/flight/client.py get localhost:2000 -c foo
   ```
   
   Without this patch, if you Ctrl-C, your client will still be stuck forever. With this patch you'll interrupt the call as expected.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org