Socket Performance

castironpi at gmail.com castironpi at gmail.com
Sat Mar 15 23:08:05 CET 2008


On Mar 15, 8:18 am, Bryan Olson <fakeaddr... at nowhere.org> wrote:
> castiro... at gmail.com wrote:
> > Gabriel Genellina wrote:
> >> No need to reinvent the wheel. socket objects already have a makefile  
> >> method returning a file-like object, which behaves like a buffered socket.
>
> That wheel is far from round, and needs some reinvention. Python's
> file-like objects do not play nice with lower level calls, which
> would be tolerable if they supported some well-defiend high-level
> asynchronous I/O, but they do not.
>
> > Newbie question:  Can you write to the 'file-like object' a pickle,
> > and receive it intact-- as one string with nothing else?
>
> Yes, but there's a world of gotcha's. Sockets do not recognize
> record boundaries, and Python's 'pickle' has holes one's enemies
> could drive a truck through. Still, you can pickle, write, read,
> un-pickle, and get back your data intact.
>
> > I want to know because I want to send two pickles.
>
> "Two pickles" sounds like a tasty snack, but also suggests you may
> be playing hopscotch in a minefield. This is a helpful group. Give
> us more to go on, and you are likely to receive thousands of
> dollars worth of consulting for free.

It depends on the situation.  How generally applicable is this:

fun ListenerGeneric( port, factory, arrivedfun ):

which calls 'factory' on socketA.accept (and loops again), then
arrivedfun( stringA ) on message complete detection.  ?.  It should
start itself in a separate thread.

Or is this any better:

for x in connections():
   startnewthreadwith x:
      for y in messages( x ):
         arrivedfun( y )



More information about the Python-list mailing list