I've looked around for information on writing threaded plugin code,
but I'm not having much luck. (Of course, part of the problem has to do with the overloading of the words "thread" and threaded". <g>) Does anyone here know the ropes?
I have a plugin that needs to scan a directory for the presence of new files, processing and removing them when they appear. Something like this:
loop do # Loop forever, handling files.
paths = Dir.glob(patt)
if paths.empty? # Nothing to do; zzz...
sleep(0.05)
else # Process incoming messages.
paths.each do |path|
process_input(path)
break if @terminate_bd
end
end
break if @terminate_bd
end
If I run this code in my plugin, it works just fine. Unfortunately, it also makes SketchUp unresponsive to other input, keeps the Ruby Console from updating, etc. So, I tried giving the code its own Thread:
Thread.new do
loop do # Loop forever, handling files.
...
end
end
This doesn't tie up SketchUp, but it doesn't work, either. In fact, it appears that the code in the thread never gets run at all. Comments? Clues? Suggestions?
-r