lua-users home
lua-l archive

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


Hi,

 

I have a problem with using different lanes to start commands with popen simultaneously. The read()s seems to block all other lanes resulting in a sequential behaviour?

 

To reproduce, run:

require("lanes")

 

function run(i)

    local file = io.popen("sleep 5", "r")

-- local output = file:read("*a")

    file:close()

    print("finished " .. i)

end

 

local measurements = {}

local lane = lanes.gen("*", run)

for second = 0, 10 do measurements[second] = lane(second) end

for second = 0, 10 do measurements[second]:join() end

 

=>

# time ./test.lua

finished 1

finished 0

finished 3

finished 4

finished 5

finished 2

finished 9

finished 6

finished 7

finished 10

finished 8

 

real    0m5.016s ßpopen sleeps are executed in parallel, which to me is the expected behaviour

 

Then uncomment the file:read() line and run again

=>

# time ./test.lua

finished 0

finished 3

finished 1

finished 2

finished 6

finished 5

finished 9

finished 8

finished 7

finished 10

finished 4

 

real    0m45.043s ß popen sleeps are executed (almost) sequentially

 

Kind regards,

Fredrik Widlund