I think it is more portable (and much simpler) to use the \nonstopmode macro at the beginning of the file.
We (I) use -interaction=nonstopmode in another incidence as well. We should fix them both.
Also, at a time when everybody wants to use only almost-prerelease software in LyX, code like os.write(fd, r''' \documentstyle{article} \begin{document}\end{document} ''') has a rather 1980's taste :) More seriously, initializing the whole latex machinery takes time.
Sorry, but what exactly smells stale in the above code? Bo