0

I have a situation where 2 separate scripts are running timers and will execute a call to the same module method at exactly the same time (with different arguments of course).

Will this cause a problem?

Adam Paul
  • 35
  • 1
  • 9
  • It is dependant on what you are running but if both scripts are just calling a function and that function does not access global information then it should be fine. – Zac Todd Sep 30 '20 at 00:04
  • @ZacTodd Well, its calling the __init__ function, aka a class, but its a class with just one method, __init__ – Adam Paul Sep 30 '20 at 00:06
  • In general, there is no problem with running something in two different places. The problems would only occur depending on what you want to do. – Zac Todd Sep 30 '20 at 00:09
  • @ZacTodd it just opens and appends a new line to a file. Pretty quick – Adam Paul Sep 30 '20 at 00:10
  • If you creating a new class each time then and running a function based on the information of that class then there will be no issues. But if you running from two scripts you will be creating two instances of the module so they won't interact. – Zac Todd Sep 30 '20 at 00:11
  • If the write is just adding a new line at the end of the file there may be an issue as one script could have the file open and the other tries to write, which will cause an error. – Zac Todd Sep 30 '20 at 00:13
  • @ZacTodd, thats exactly what I am worried about. – Adam Paul Sep 30 '20 at 00:18
  • You could check if the file is open and if it is wait until it closed. – Zac Todd Sep 30 '20 at 00:21
  • Good idea, not so trivial to actually make that work though – Adam Paul Sep 30 '20 at 00:29
  • This should help https://stackoverflow.com/questions/6825994/check-if-a-file-is-open-in-python – Zac Todd Sep 30 '20 at 00:30

0 Answers0