I have some sensors attached to the Raspberry Pi which I'm interfacing with several python scripts. When run on their own they output normally to stdout. When writing to a pipe I already found out I need to flush the buffer or it won't be seen by a plain lua script.
Code: Select all
python3 -u script.py
print(str, flush=True)
sys.stdout.write(str)
sys.stdout.flush()
This is the minimal thread code
Code: Select all
print("motion_thread: starting...")
local p = assert(io.popen("python3 /home/pi/zapview/python/motion_detection.py", "r"))
if not p then
print("motion_thread: motion_detection.py error")
end
print("motion_thread: motion_detection.py process: " .. tostring(p))
while p do
local line = p:read("*l")
if line then
print("motion_thread: "..tostring(line))
love.thread.getChannel("motion"):push(true)
end
end
p:close()
It mostly seems to appear when I'm using more then one of those threads (different files launching different scripts). And when they hang they hang the whole love game unless I put in a sleep at the start of each thread
Code: Select all
local function sleep(n)
os.execute("sleep " .. tonumber(n))
end
sleep(5)
Code: Select all
local f = os.tmpname()
printf("motion_thread: using tmp file: "..f)
os.execute("python3 /home/pi/zapview/python/motion_detection.py > "..f)
for line in io.lines(f) do
printf("motion_thread: "..tostring(line))
love.thread.getChannel("motion"):push(true)
end
os.remove(f)
The most minimal python script I can reproduce this with
Code: Select all
#!/usr/bin/env python3
import sys
import time
while True:
# print("test")
sys.stdout.write('test')
sys.stdout.flush()
time.sleep(1)
I've compiled love from the love-xxx-linux-src.tar.gz files in the bitbucket repo with configure and make. I'm getting the same behavoir from 11.0, 11,1 and 11.2.
I'm stuck with this problem for more then a week now, and it's a game for a video art installation that is going to be displayed in a few days, so if anyone is able to help me solve this or work around it that would be greatly appreciated.