[SOLVED] Tasks not executing in parallel


#1

1) Give a description of the problem
The routine is not executing in parallel the comends that are inserted inside a IF

2) What is the expected behavior?
Commands shoulb be executed at the same time, but instead of that , it executes one and wait that to end to execute the other one

3) What is happening/not happening?
Line 21 is waiting line 15 (IF to finish execution - after 2 minutes) and they should execute in parallel as it was

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS THEN HIGHLIGHT ALL OF THE LOGS SND CLICK ON THE </> ICON TO FORMAT THEM)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

Yeah, that is how pistons work by default. They execute synchronously. So one step at a time.

If you want them to execute multiple steps at the same time (or as close to that as possible), then you have to modify the default behavior and make is so that the commands you want to execute at the same time run asynchronously.

To do that you click on the “with” (in your piston) and then select the cog at the bottom and then change the Execution Method.


#3

Wouldn’t you actually want to enable Parallelism in the piston settings.


#4

Also, don’t you have to have a “with” for the second set of commands? They’re just kinda hanging out there in limbo. Don’t you have to have “with location” selected for the device?


#5

Nope. That’s an entirely different thing. He wants asynchronous execution Parallelism at the piston level would be used if he made something would could potentially spawn multiple instances of the same piston. This isn’t doing that…

That is how those are already. If you only put actions into a “location” (as opposed to putting them in a “device”) they show up that way. Perfectly fine as is.


#6

Really? Why do mine always show up with the with listed as location? Am I doing something wrong?
download


#7

I have been using that all wrong…thanks for clearing that up!


#8

Different… But not wrong. As they say around here “open world” so you can pretty much do it however you like. Inside the piston in Edit mode they would look like this:

image

But when saved they look like this:

image

image


#9

Ah…I’m not using Location, I’m using $Location. Evidently, they are different. :smiley:
When you use $location, the with shows up in display and edit mode.


#10

As I said, “Open world”. :slight_smile:


#11

fyi async only matters when there is a wait statement. each async statement tells the piston to not pause execution at the next wait and continue executing the piston with the statement following the with block containing the wait.

also fyi piston parallelism when turned on creates a 2nd instance of the piston to handle incoming events. while there will be 2 instances of the piston all variables in the define block are shared and each piston does not get its own instance of variables.


#12

Hey sir;

I didnt see that way. The “with” came because I needed to use a device and put some following commandas for that device alone. Is there another way to write that and do the same thing?


#13

Done for it and worked flawlessly. Is there an way for setting this by default? Because if I want something for wait I would put that inserted into the code anyways.


#14

So, async doesn’t start all with’s for the same if at the same time, it just skips the wait? Am i getting that correct? This is getting more confusing rather than less. LOL Just when you think you understand something…

Also, if you set up two piston with the same trigger included in both, will both fire at the same time by default or do you have to engage parallelism to get them to both fire?


#15

Not that I’ve ever seen. You have to set it each time you want it that way. You’d probably have to ask for a new feature to get this to be happen.


#16

async tells webcore to not pause the piston at any wait timer within the async block rather continue execution with the statements after the async block.

two pistons with the same trigger would both receive the same event and get triggered without parallelism being set. parallelism is only required when you want two copies of the same piston to run and handle events that meant for just that piston. each event meant for that piston will be sent to one of the copies of that piston.


Passing variables through pistons
#17

if there is no wait statement in the code then using async serves no purpose.


#18

Thank you! This finally makes sense.


#19

@bangali I am trying to execute the use case you’re describing, i.e., I am spawning multiple pistons that are executing on different devices, however I cannot get this to work. The device is getting passed as an $arg to the spawned piston, but it’s not controlling all of them properly. They do correctly receive the ‘Turn On’ command when called, but only the last one gets the Turn Off command.


#20

start a new thread with a green snapshots of the pistons? :slight_smile: