Something like asynchronous XML-RPC possible?

Martin v. Löwis martin at v.loewis.de
Sat Jan 25 07:03:50 EST 2003


hwlgw at hotmail.com (Will Stuyvesant) writes:

> If they say that creating a thread for this is highly inefficient
> and a wrong design, what should my answer be?

Don't create a thread, then: the objection is valid that creating a
thread for each outgoing request is expensive. Instead, put the open
connection into a list of connections to process. Use select to find
out what connections are ready to have the results read from. On
sending each new request, first send the request, then check all open
connections, and close then ones that have completed.

Alternatively, have a single thread that collects all open
connections. Use a queue to pass new connections to that thread. If
there are no new connections, that thread will block, waiting for
work. If there are open connections, the thread will process the
responses one-by-one (or many of them simultaneously using select).

Neither of these two approaches require changes to the server side.

If changing the server side is acceptable, you can use a variation of
"XML-RPC without response", where you don't expect to get a response
back. You can then send the request over TCP, and immediately close
the connection. On the server side, you must suppress the sending of
the response.

Of course, you could also use a protocol that has oneway invocations
builtin, such as CORBA or Pyro.

Regards,
Martin




More information about the Python-list mailing list