Python multiplexing is too hard (was: Network statistics program)

Cameron Laird claird at starbase.neosoft.com
Thu May 18 01:55:13 CEST 2000


In article <sZBU4.1751$%8.7965 at news1.onlynews.com>,
Greg Fortune <gfor_ewu at ispchannel.com> wrote:
>Right now, I'm just sending the output of the ping to a text file and then
>reading it from there.
>
>os.system('ping -t 1 208.152.8.1 > convertor_temp.txt')
>#Read input file and extract result
>#Store result
>
>  That circumvents the need for the select.  The only reason I've done this
>is because the os.system call will not return the output from the call (and
>I'm very new to this language as well as "real-world" programming <g>).  Is
>there another way (possibly the select you mentioned) to get the output from
>a call back to the program?  I need to use this on both Linux and Windows so
>I can't use the UNIX specific commands module.
>
>Greg
>
>Cedric Adjih <adjih at crepuscule.com> wrote in message
>news:8ftqtk$25a$1 at ites.inria.fr...
>>
>> You can use module time, function sleep:
>>   time.sleep(1.1) # sleep 1.1 seconds
>> Or if you are waiting for events or for a timeout, select
>> will be helpful:
>>   select.select([file desc list]..., timeOutInSeconds)
>> For instance if you are waiting for a ping reply.
>>
>> -- Cedric
>>
>
>

What's the really cool, idiomatic way to multiplex in Python?
I'm not happy with anything I do in this regard.

First, I recognize this is far afield from Mr. Fortune's
needs.  He's best served either by direct ICMP calls, or a
simple
  os.popen("ping -c 1 ...").read()
which gives him all of what I understand he's after.  Mr.
Fortune, let me know if it's not obvious how this answers
your question, and I'll be more explicit.

Suppose, though, that he really did need multiplexing.  Is
there a tutorial I haven't noticed yet that models the Python
way to process (let's call them) stream-based events?  We can
put stuff in a thread, but that's a lot of mechanism; we can
select, but, gosh, isn't that the low-level error-prone OS
system-level programming Python's s'posed to transcend?  All
the Python code I've seen in this area just "has too many
notes".  It makes me think it's fragile.
-- 

Cameron Laird <claird at NeoSoft.com>
Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



More information about the Python-list mailing list