Questions about asyncore

Frank Millman frank at chagford.com
Wed Jul 30 03:49:36 EDT 2008


On Jul 29, 3:40 pm, "Giampaolo Rodola'" <gne... at gmail.com> wrote:
> On 29 Lug, 13:09, Frank Millman <fr... at chagford.com> wrote:

Thanks for the reply, Giampaolo.

>
> The benefit of asynchat is that it automatically handles the buffering
> of both input and output.
> Aside from set/found_terminator() the other two methods you could want
> to look at are push() and push_with_producer().
> push() is a buffered version of asyncore.send(), push_with_producer()
> accepts a data-producer object you can use in case you want to deal
> with something other than strings (e.g. files, lists, generators, and
> so on...).
>

I looked at push() and push_with_producer(). To be honest I don't
fully understand why I would want to use them yet - I will have to go
over them a few more times. However, my handle_write() method seems to
be working ok and is not complicated, so I will stick with that for
now.

>
> I'm not sure to understand but I doubt you have to use a thread.
> If you "have to wait for the reply before continuing" just implement
> this logic into handle_read() or found_terminator() method.
>

Maybe I am a bit slow, but I cannot figure out how to do this without
adding a lot of complication. I will try to give a simple example.

My server is a database server. It sits between the actual database
and the client, and implements access control, automatic handling of
foreign keys, etc. It accepts messages to read, update, and write
data, and returns the results.

For testing purposes, I want the client to send and receive messages
such as the following (pseudocode) -

-> Read Customer record with CustNo = 'A001'.
<- Print data, check that it is correct. [1]
-> Read customer's Branch record.
<- Print data, check that it is correct.
-> Update Customer record with new Branch code. [2]
-> Read Branch code from Customer record.
<- Print code, check that it has changed.
-> Read customer's Branch record.
<- Print data, check that it belongs to the new Branch.

[1] Amongst other things, the server returns the id of the record
[2] The update request uses the record id to identify which record to
update

These are just examples of the tests I might want to throw at the
server. With my multi-threaded approach, the asyncore loop runs in the
background, and in the foreground I can easily send any message I like
and check the results. I cannot see how to implement this using
handle_read() and found_terminator().

Maybe you can give a simple example of an alternative approach.

Thanks

Frank



More information about the Python-list mailing list