bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] Problem with printing 5000 lines to a coprocess


From: Hermann Peifer
Subject: [bug-gawk] Problem with printing 5000 lines to a coprocess
Date: Sat, 20 Dec 2014 13:41:03 -0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

Hi again,

I am trying to use a two-way pipe as explained in the manual [0]. This works fine when printing a small number of lines to geod [1] or inverse [2] utilities, but not for larger amounts of lines, say: 5000. My sample code [3] hangs after printing some 4000+ lines, see [4].

I am wondering if there is some buffer setting or similar to avoid the problem. Maybe this is not a gawk issue in the first place, as printing 100000 lines to sort works fine.

Regards, Hermann


[0]
http://www.gnu.org/software/gawk/manual/html_node/Two_002dway-I_002fO.html#Two_002dway-I_002fO

[1] http://trac.osgeo.org/proj/browser/trunk/proj/src/geod.c

[2] http://geographiclib.sourceforge.net/html/C/inverse_8c_source.html

[3] cat test.awk

BEGIN {

        if (! num)
                num = 100

        a[1] = "inverse"
        a[2] = "geod -I +ellps=WGS84"
        a[3] = "LC_ALL=C sort -nr"

        command = a[cmd in a ? cmd : 1]

        for (i = 0; i < num; i++) {
                v1 = i / 1000
                v2 = (i + 1) / 1000
                print v1, v1, v2, v2 |& command
                print "w", ++write ":", v1, v1, v2, v2 > "/dev/stderr"
        }
        close(command, "to")

        while ((command |& getline line) > 0)
                print "r", ++read ":", line
        close(command)
}

[4]

# Works as expected: printing 100 lines to inverse utility
$ awk -v cmd=1 -f test.awk | tail -3
...
w 98: 0.097 0.097 0.098 0.098
w 99: 0.098 0.098 0.099 0.099
w 100: 0.099 0.099 0.1 0.1
r 98: 45.192380332960596 45.192382034655800 156.9033606093
r 99: 45.192379457591720 45.192381176740184 156.9033583141
r 100: 45.192378573377802 45.192380309979541 156.9033559955

# Hangs after printing 4329 lines to inverse utility
$ awk -v cmd=1 -v num=5000 -f test.awk | tail -3
...
w 4327: 4.326 4.326 4.327 4.327
w 4328: 4.327 4.327 4.328 4.328
w 4329: 4.328 4.328 4.329 4.329
^C

# Hangs after printing 4963 lines to geod utility
$ awk -v cmd=2 -v num=5000 -f test.awk | tail -3
...
w 4961: 4.96 4.96 4.961 4.961
w 4962: 4.961 4.961 4.962 4.962
w 4963: 4.962 4.962 4.963 4.963
^C

# Works as expected: printing 100000 lines to sort utility
$ awk -v cmd=3 -v num=100000 -f test.awk | tail -3
...
w 99998: 99.997 99.997 99.998 99.998
w 99999: 99.998 99.998 99.999 99.999
w 100000: 99.999 99.999 100 100
r 99998: 0.002 0.002 0.003 0.003
r 99999: 0.001 0.001 0.002 0.002
r 100000: 0 0 0.001 0.001



reply via email to

[Prev in Thread] Current Thread [Next in Thread]