determine if os.system() is done

C

Christos Georgiou

He's 37 years old! How long should one be given to mature?

I (lots of female friends, actually :) believe many men remain in
puberty for longer than that.
 
L

Leif K-Brooks

Xah said:
i switched to system call with tail because originally i was using a
pure Python solution

inF = gzip.GzipFile(ff, 'rb');
s=inF.readlines()
inF.close()
last_line=s[-1]

and since the log file is 100 megabytes it takes a long time and hogs
massive memory.

How about:

inF = gzip.GzipFile(ff, 'rb')
for line in inF:
pass
last_line = line

It's a bit slower than gzip and tail, but the memory usage is fine.
 
F

Fredrik Lundh

Fredrik said:
zcat|tail is a LOT faster.

and here's the "right way" to use that:

from subprocess import Popen, PIPE
p1 = Popen(["zcat", filename], stdout=PIPE)
p2 = Popen(["tail", "-1"], stdin=p1.stdout, stdout=PIPE)
last_line = p2.communicate()[0]

(on my small sample, this is roughly 15 times faster than the empty for loop)

</F>
 
X

Xah Lee

isn't there a way to implement tail in python with the same class of
performance?

how's tail implemented?

Xah
(e-mail address removed)
∑ http://xahlee.org/

Fredrik said:
Fredrik said:
zcat|tail is a LOT faster.

and here's the "right way" to use that:

from subprocess import Popen, PIPE
p1 = Popen(["zcat", filename], stdout=PIPE)
p2 = Popen(["tail", "-1"], stdin=p1.stdout, stdout=PIPE)
last_line = p2.communicate()[0]

(on my small sample, this is roughly 15 times faster than the empty for loop)

</F>
 
M

Michael Sparks

Xah said:
isn't there a way to implement tail in python with the same class of
performance?

how's tail implemented?:

Those crazy open source developers have an implementation here:
http://cvs.sourceforge.net/viewcvs....sybox-0.60.5/Attic/tail.c?rev=1.1&view=markup

It's not documented. It's pretty short though, I'm sure you won't have any
problems <strike>ripping it to pieces</strike> understanding it.

If it is a problem, a more documented version here (however I'm sorry, this
also by those open source/free software people you love to attack):

http://www.koders.com/c/fid8DEE98A42C35A1346FA89C328CC3BF94E25CF377.aspx

If you want something not by open source crazies (as you like to refer to
us), you may prefer this link:
http://minnie.tuhs.org/UnixTree/V7/usr/src/cmd/tail.c.html

However that's even less documented (despite being not open source, just
"visible"), and more obfuscated.

As a compromise, you could always look at plan 9's implementation here:
* http://swtch.com/usr/local/plan9/src/cmd/tail.c

If you're after alternatives, you could always try here: (where all these
links came from)
http://www.google.com/search?q=tail.c

Fairly informative set of links provided by that highly non-obvious
search....

Hope that helps,

Best Regards,


Michael.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top