How to set up multiple parallel running processes

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

How to set up multiple parallel running processes

Post by mrcoollion » Thu Aug 15, 2019 1:14 pm

Hello fellow LC enthusiasts,

I have a question about how to best setup multiple non blocking parallel running processes in LC.
What I am planning to build is an application that has approx. 20 processes running simultaneously.
Each process must get data from a Server in 30 sec intervals and communicate back in the same interval. I use TsNet for this (Post & Get) that uses a REST-API.
Each process has its own graphical user interface with controls and I have a overview interface.

So my question is, how best to set this up. Should or can I:
1) Place each process in a separate Stack and have a stack with the user interface and user controls that communicates with those other separate stacks?
2) Place each process in Sub-Stacks with each sub stack having the sub user interface a process controls. And the Main Stack handles the overview user interface and user controls and communicates with the sub-stacks?
3) Can I place all in one stack with cards and routines (Commands)?
4) Other options ?

So some much needed advice (maybe with example) would be appreciated so I will not be running in the wrong direction coming to the conclusion after having spend many hours that I need to start from scratch again?

Friendly greeting,

Paul (MrCoolLion)

Klaus
Posts: 13821
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to set up multiple parallel running processes

Post by Klaus » Thu Aug 15, 2019 1:18 pm

Dag Paul,

since LC is single-threaded, the only way to come near to your goal might be using "send" a lot.


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9633
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to set up multiple parallel running processes

Post by dunbarx » Thu Aug 15, 2019 1:45 pm

I think I see what you are after, but why not just "thread" several processes. Given a field and a button with:

Code: Select all

on mouseUp
   doLotsOfStuff
end mouseUp

on doLotsOfStuff
   if the optionKey is down then exit to top
   put random(99) into fld 1
   wait 10 with messages
   doOtherStuff
end doLotsOfStuff

on doOtherStuff
   put any char of "XYZ" into fld 1
   wait 10 with messages
   doEvenMoreStuff
end doOtherStuff

on doEvenMoreStuff
   put any item of "Zebra,horse,dog" into fld 1
  wait 10 with messages
   doLotsOfStuff
end doEvenMoreStuff
Klaus' suggestion of sending messages in time would work as well. Each method invokes a well-formed handler, and these can be executed as desired, based on nothing, or any preset or other conditions.

Craig

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: How to set up multiple parallel running processes

Post by Mikey » Thu Aug 15, 2019 2:49 pm

isnt tsnet asynchronous? if it is then you get multithreadedness by effect.
scheduling can be done lots of ways. i have a cron-ish library at https://github.com/macMikey/mikeys-cron-library. it is designed to be a levure helper but there is no reason why it cant be tweaked so that it is independent.
there are examples of running multiple lc threads/processes in various places. during last year's LCG there was a session on that very topic. it is very straightforward. you can also have multiple LC server instances running to do this.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9820
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to set up multiple parallel running processes

Post by FourthWorld » Thu Aug 15, 2019 6:25 pm

What is being done with the data during the time between downloading and re-uploading? And what is the size of the data being transferred?

Applications are often network-bound rather than CPU-bound, and the optimal solution will benefit from knowing which is the case here.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: How to set up multiple parallel running processes

Post by mrcoollion » Thu Aug 15, 2019 6:41 pm

Thanks for the excellent suggestions. I will test what fits best... and inform about the solution i finally choose.
@FourthWorld
The data send and received is very little so it should not be a source of concern.
The application has several processes running which are all similar (in fact exactly the same code but different parameters). At least Every thirty seconds maybe more often each proces requests data from the server and based upon this data and some algorithms does an action towards the same server or not.

Thanks for the help everybody and do not hesitate to place more suggestions of example code :D
Regards,

Paul (MrCoolLion)

Post Reply

Return to “Talking LiveCode”