Let's say we have two different notebooks note1.nb and note2.nb performing calculations on two different kernels simultaneously. Both of them need to access and write to a file file.txt. However, clearly they cannot write to the file simultaneously, so each should implement a waiting loop for as long as file.txt is being used by the other notebook. To do that, we need a way to determine in Mathematica whether file.txt is currently being used or not.

Therefore, my question is:

Is there a function in Mathematica that determines whether a file is currently being used by a different process? (By a different Mathematica kernel in particular?)

Perhaps there is some convenient workaround way of determining that? Thanks for any suggestion!

  • 2
    $\begingroup$ I don't think there's a way to check this, but you could try an OpenAppend to WriteString without danger of overwriting. Obviously this is unsatisfying and might lead to some weird race conditions or something, though. $\endgroup$ – b3m2a1 Jan 30 '18 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.