0

I execute python script from browser via lua script:

os.execute('python scriptname.py --arg1 Test --arg2 Test2')

and I do it again (e.g. by refreshing the page, sending the form)

os.execute('python scriptname.py --arg1 Test3 --arg2 Test4')

I would like the second script to be executed only when the first script is done to the end. I would like the scripts to be added to the queue and executed from the oldest script to the newest. How can I do this?

brianolive
  • 1,573
  • 2
  • 9
  • 19
kst
  • 51
  • 1
  • 4

1 Answers1

0

This is a very similar question to a discussion thread that I am part of for Lua in Codea (Lua development environment for the iPad): See here. On that page, follow se24vad’s use of a thread queue. Note that code on that page is not necessarily portable, since Codea provides some functionality not built in to Lua. I point to this page for the ideas, not for the specific code.

Basically, the idea is that you need to queue up the functions in a thread queue (i.e. Lua coroutines). In his particular implementation you do not move on to a new coroutine until the one at the top (index 1 in the queue table) is complete. In other words, the coroutine calls are blocking.

You will want to implement a coroutine queue, with each of your os.execute calls as a separate coroutine.

Now, how that fits in to the rest of your code, I am not sure. I do not know what code you have that controls when your page refresh happens. You would need some sort of controller code to keep track of the coroutine queue.

If a thread queue isn’t possible in your use-case, then maybe the python scripts need to somehow report completion back to the browser. When a new execute call is made, it checks the completion variable first before proceeding.

brianolive
  • 1,573
  • 2
  • 9
  • 19