0

I'm using a bunch of python scripts to simulate sensor network behaviour. In particular, I want to simulate some sensors which asynchronously send readings to a MQTT broker. In order to do that I wrote some scripts where each one represents a different sensor.

Looking at: stackoverflow old question

I preferred not revive an old question. Anyway I used that approach:

script1.py &
script2.py &
script3.py &
script4.py &...

My question is: is that a real concurrency? if I try to print received readings (on console) sometimes I obtain, for instance, some readings belonging to script1, than one from script 3, than four from script 2 and so on... When honestly I expected no consequents readings from the same script. Is this a problem of the printing or maybe the & don't assure a real concurrency between the scripts?

I'm developing with osx.

Maybe there is a more realistic way to simulate sensors behaviour?

Akinn
  • 1,896
  • 4
  • 23
  • 36
  • Not sure, but maybe printing a few before switching processes is the best way the OS thought? Roughly all processes with same priority should get equal CPU time, maybe that's the amount of processing each process carries out in given time, what makes you think it's not concurrency? BTW when you use '&' you're just shell asking to run your python script in background, so it's the shell and in turn the OS which is responsible for concurrency. – 0xc0de Jul 28 '17 at 16:25
  • Interesting, so I can't be sure that it's real in concurrency because everything is handled by the os. Then in your opinion there are no other ways to simulate that? – Akinn Jul 28 '17 at 16:54
  • You might want to try looking into a simulation framework like simpy - https://simpy.readthedocs.io/en/latest/ – OldGeeksGuide Jul 28 '17 at 17:03

0 Answers0