Synchronous Python command

Synchronous Python command

tomi_kosunen
Not applicable
23 Views
5 Replies
Message 1 of 6

Synchronous Python command

tomi_kosunen
Not applicable

[ FlexSim 23.1.1 ]

Hi. How do execute synchronous Python command? I'm sending queries to a server from Python command. It takes some time to get an answer from the server so I need to stop the FlexSim clock for that time. In Http request I can use request.sendAndWait(); but how the same is done with Python?

In the example, the server response delay is modelled with sleep command in Python code. The Processor is asking for a process time from Python.

testWait.fsm

time_funktio.py

0 Likes
Accepted solutions (1)
24 Views
5 Replies
Replies (5)
Message 2 of 6

kavika_faleumu
Autodesk
Autodesk
Accepted solution

Hey @Tomi Kosunen, there are a few resources I can point you to to help you setup your queries. Here's a post I made a few months back about someone wanting to run an experimenter, updating parameters through python and a server/client connection. It uses the serverreceive() command which has the option to block the model (i.e., the server) from running until it receives a message from your python code (i.e., the client). There are some custom User Commands to simplify the process in the model from the post, so be sure to take a look at those.

1682528885202.png

0 Likes
Message 3 of 6

tomi_kosunen
Not applicable

Thanks @Kavika F Are you sure you linked the correct reference to a earlier post? The " a post I made a few months back" goes to question about AGV trigger and I cannot find anything about Python nor socket connectons.

0 Likes
Message 4 of 6

jason_lightfootVL7B4
Autodesk
Autodesk
Message 5 of 6

tomi_kosunen
Not applicable

Thanks @Kavika F . So if I understand correct, the solution would be to open socket connection to Python api and then run Python thru that connection. It would probably work but in this case I think I'll just convert the Python code to FlexScript and use the sendAndWait() command instead.

0 Likes
Message 6 of 6

kavika_faleumu
Autodesk
Autodesk
Yes that is certainly one way you could do it. Using the client/server and socket commands would be useful. You could also try using coroutines and await statements if you have specific events or time in FlexSim you're waiting for, but I'm less certain about that approach.
0 Likes