Python Asynchronous Services

Graeme Matthew gsmatthew at
Thu Jul 17 13:27:00 CEST 2003

Hi all, I have hit a serious snag ...

I am writing an app server. I am happy with pythons threading etc however I
am totally confused with handling large request on a socket. For example I
can create a threadingTCPServer, the script that calls the app server might
send a file or an xml request. Where I am stuck is how do you handle large
files ?

for example:

while 1:
    data = recv(1024)
    if not data: break

surely in a thread this will block all other threads until all data is
recieved. I have also been told that one cannot rely on this mechanism as
the socket might end up in a continious loop, i.e you need to send a header
included in the data that states the length (bytes) that is been sent, or
you need some terminator, what happens if the terminator is within the
requests data and not at the end ?

please any help or examples as I have now been on this for 2 days without
any luck. I have looked at asyncore and asynchat, problem is once the server
socket input is completed then their will be an area that is CPU bound where
it will need to call the model, database etc and produce the html request,
this means that control will only be handed back to IO operations when this
is finished, effectively blocking all other requests  ....

I suppose another question is can python handle large files and requests at
the same time or is one better off simply forking the process even though
its costly ?

Many thanks .....

More information about the Python-list mailing list