[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Any tips on 2 process vinyl to file converter?
- From: Michal Kolodziejczyk <miko@...>
- Date: Thu, 27 Jan 2011 13:11:12 +0100
On 27.01.2011 00:30, Steve Litt wrote:
> Notice that the digitizer process polls the queue. I'd like the input process
> notify it every time a new file is pushed on the queue, but it was tough using
> shellscripts.
I would use pipes (assuming you are using linux/unix). It is easy then.
> I'm thinking of redoing this in Lua. Can coroutines be run in two different
> xterms? Can coroutines signal each other? Would you even recommend coroutines?
No. Yes. No.
Coroutines are like a functions called at some point in your code. Can
you see the output from two different functions in different xterms? (I
mean without "hacking").
> Does Lua have facilities to send Linux signals? Might they communicate via
> sockets? Any other words of wisdom?
Do you want to build a cross-platform solution, or just a short script
for your environment? It it is for yourself, and you want it to "just
work", i would use 2 processes using unix pipes (or tcp sockets with
luasocket).
I am attaching sample solution using named pipes. (run "lua vinyl.lua"
for the first process and "lua vinyl.lua something" for the second one).
Regards,
miko
function pop_queue()
if not INPIPE then
INPIPE=io.open('/tmp/pipe','r')
end
local filename=INPIPE:read('*l')
return filename
end
function push_queue(filename)
if not OUTPIPE then
OUTPIPE=io.open('/tmp/pipe','w')
OUTPIPE:setvbuf ('line')
end
OUTPIPE:write(filename.."\n")
end
function meta()
print('METADATA INPUT LOOP PROCESS')
os.execute('mkfifo /tmp/pipe')
local ID=0
for line in io.lines() do
ID=ID+1
print('Line=', line)
outfilename="/tmp/file"..ID
fp=io.open(outfilename,'w')
fp:write('Meta: '..line)
fp:close()
push_queue(outfilename)
end
print('EXIT')
push_queue('QUIT')
end
function digitizer()
print('DIGITIZER/CONVERTER LOOP PROCESS')
local filename=pop_queue()
while filename~='QUIT' do
print('Got file:', filename)
print('Got meta:', io.open(filename,'r'):read('*a'))
filename=pop_queue()
end
print('FINISHED')
end
if arg[1] then
digitizer()
else
meta()
end