[Tutor] piping continuous output

Koen Bossers koen@behindthesofa.dhs.org
Wed, 25 Jul 2001 15:12:27 +0200


This is a multi-part message in MIME format.
--------------976BC1FF29007423AF83F397
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

sill@optonline.net wrote:

> Look at pctail.py program on vaults of parnassus, it does something
similar
> (reads from growing log files).

Not what I had in mind. I want to avoid creating temporary files. That's
why I
chose popen, else I would have used something like os.system('command >>

/tmp/tempfile') or something.

OK second try: some VERY weird behaviour here:

[print_messages.py]
#! /usr/bin/python

import time, os

counter = 0
while counter < 5000:

    print '%d'%counter

    time.sleep(0.01)
    counter = counter + 1

[popentest.py]
#! /usr/bin/python

## test popen with continuing output

import os, time, string
import popen2


child = popen2.Popen3('./print_messages.py')
output = child.fromchild

count = 1

print "starting...", os.getpid()
listing = ''
start = time.time()

while child.poll() == -1:        ## if child is still running...

    print count, time.time()-start
    test = output.read(100)

    count = count + 1
    time.sleep(0.2)


output when i run popentest.py:

starting... 414
1 after 0.000128984451294
2 after 10.696469903
3 after 10.896476984
4 after 11.0964080095
5 after 11.2964220047
6 after 11.4964289665
7 after 11.6964190006
8 after 11.8964159489
9 after 12.0963799953
10 after 12.2964549065
11 after 12.4964559078
12 after 12.6964579821
13 after 12.8963899612
etc...

Notice the major timediff between step 1 and 2! 10 seconds!!!! what the
hell
is happening here? I know Python isn't always that fast, but why this
big
delay? Enlighten me!

Cheers,

Koen Bossers

--------------976BC1FF29007423AF83F397
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

X-Mozilla-Status2: 00000000
Message-ID: <3B5EC445.57AE55D0@behindthesofa.dhs.org>
Date: Wed, 25 Jul 2001 15:06:13 +0200
From: Koen Bossers <koen@behindthesofa.dhs.org>
X-Mailer: Mozilla 4.78 [en] (X11; U; Linux 2.4.4 i686)
X-Accept-Language: en
MIME-Version: 1.0
To: ak@silmarill.org
Subject: Re: [Tutor] piping continuous output
References: <3B5EA1DA.943F649@behindthesofa.dhs.org> <20010725081741.B321@sill.silmarill.org>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit



sill@optonline.net wrote:

> Look at pctail.py program on vaults of parnassus, it does something similar
> (reads from growing log files).

Not what I had in mind. I want to avoid creating temporary files. That's why I
chose popen, else I would have used something like os.system('command >>
/tmp/tempfile') or something.

OK second try: some VERY weird behaviour here:

[print_messages.py]
#! /usr/bin/python

import time, os

counter = 0
while counter < 5000:

    print '%d'%counter

    time.sleep(0.01)
    counter = counter + 1

[popentest.py]
#! /usr/bin/python

## test popen with continuing output

import os, time, string
import popen2


child = popen2.Popen3('./print_messages.py')
output = child.fromchild

count = 1

print "starting...", os.getpid()
listing = ''
start = time.time()

while child.poll() == -1:        ## if child is still running...

    print count, time.time()-start
    test = output.read(100)

    count = count + 1
    time.sleep(0.2)


output when i run popentest.py:

starting... 414
1 after 0.000128984451294
2 after 10.696469903
3 after 10.896476984
4 after 11.0964080095
5 after 11.2964220047
6 after 11.4964289665
7 after 11.6964190006
8 after 11.8964159489
9 after 12.0963799953
10 after 12.2964549065
11 after 12.4964559078
12 after 12.6964579821
13 after 12.8963899612
etc...

Notice the major timediff between step 1 and 2! 10 seconds!!!! what the hell
is happening here? I know Python isn't always that fast, but why this big
delay? Enlighten me!

Cheers,

Koen Bossers


--------------976BC1FF29007423AF83F397--