Re: Async/Concurrent HTTP Requests

2015-02-12 Thread Paul Rubin
Marko Rauhamaa ma...@pacujo.net writes:
 I have successfully done event-driven I/O using select.epoll() and
 socket.socket().

Sure, but then you end up writing a lot of low-level machinery that
packages like twisted take care of for you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Async/Concurrent HTTP Requests

2015-02-12 Thread Paul Rubin
Ari King ari.brandeis.k...@gmail.com writes:
 I'd like to query two (or more) RESTful APIs concurrently. What is the
 pythonic way of doing so? Is it better to use built in functions or
 are third-party packages? Thanks.

The two basic approaches are event-based asynchronous i/o (there are
various packages for that) and threads.  There are holy wars over which
is better.  Event-driven i/o in Python 2.x was generally done with
callback-based packages like Twisted Matrix (www.twistedmatrix.com).  In
Python 3 there are some nicer mechanisms (coroutines) so the new asyncio
package may be easier to use than Twisted.  I haven't tried it yet.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Async/Concurrent HTTP Requests

2015-02-12 Thread Marko Rauhamaa
Paul Rubin no.email@nospam.invalid:

 Marko Rauhamaa ma...@pacujo.net writes:
 I have successfully done event-driven I/O using select.epoll() and
 socket.socket().

 Sure, but then you end up writing a lot of low-level machinery that
 packages like twisted take care of for you.

Certainly. It would be nice if the stdlib protocol facilities were
event-driven and divorced from the low-level I/O.

Asyncio does that, of course, but the programming model feels a bit
weird.

Twisted documentation seems a bit vague on details. For example, what
should one make of this:

   def write(data):
  Write some data to the physical connection, in sequence, in a
  non-blocking fashion.

  If possible, make sure that it is all written. No data will ever
  be lost, although (obviously) the connection may be closed before
  it all gets through.

   URL: https://twistedmatrix.com/documents/15.0.0/api/twisted.intern
   et.interfaces.ITransport.html#write

So I'm left wondering if the call will block and if not, how is flow
control and buffering managed. The API documentation leads me to a maze
of twisted passages, all alike. From what I could gather, the write()
method is blocking and hence not suitable for serious work.

By contrast, the semantics of Python's socket.send() is crisply defined
and a pleasure to work with.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Async/Concurrent HTTP Requests

2015-02-12 Thread Zachary Ware
On Thu, Feb 12, 2015 at 10:37 AM, Ari King ari.brandeis.k...@gmail.com wrote:
 Hi,

 I'd like to query two (or more) RESTful APIs concurrently. What is the 
 pythonic way of doing so? Is it better to use built in functions or are 
 third-party packages? Thanks.

Have a look at asyncio (new in Python 3.4, available for 3.3 as the
'tulip' project) and possibly the aiohttp project, available on PyPI.
I'm using both for a current project, and they work very well.

-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Async/Concurrent HTTP Requests

2015-02-12 Thread Marko Rauhamaa
Paul Rubin no.email@nospam.invalid:

 Event-driven i/o in Python 2.x was generally done with callback-based
 packages like Twisted Matrix (www.twistedmatrix.com). In Python 3
 there are some nicer mechanisms (coroutines) so the new asyncio
 package may be easier to use than Twisted. I haven't tried it yet.

I have successfully done event-driven I/O using select.epoll() and
socket.socket().


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Async/Concurrent HTTP Requests

2015-02-12 Thread Ari King
Hi,

I'd like to query two (or more) RESTful APIs concurrently. What is the pythonic 
way of doing so? Is it better to use built in functions or are third-party 
packages? Thanks.

Best,
Ari
-- 
https://mail.python.org/mailman/listinfo/python-list