0
$\begingroup$

Before reporting this to Wolfram I want to make sure that I am not mistaken. I am using MMA version 13.0.1

The following will lock a file and then write "Hello" into it, all in the current kernel:

SessionSubmit[nam := "c:/tmp/test.txt";
 lok = nam <> "-lck";
 WithLock[lok, Put["Hello", nam]]
  ]

However, if we use a different kernel, nothing is written:

LocalSubmit[nam := "c:/tmp/test.txt";
 lok = nam <> "-lck";
 WithLock[lok, Put["Hello", nam]]
  ]
$\endgroup$

1 Answer 1

3
$\begingroup$

There is a problem in Version 13.0 with file locking in local tasks.

BUT: WithLock is HoldAll. You are not specifying a lock file, but a lock variable named "lok". Use With to force the variable value into WithLock, and also use the File[] wrapper to disambiguate.

LocalSubmit[
 nam := "/tmp/test.txt";
 With[{lok = nam <> "-lck"},
  WithLock[File[lok], Put["Hello", nam]]]]

This example will work in the upcoming version of Mathematica.

$\endgroup$
2
  • $\begingroup$ Tank you for your answer. Unfortunately in 13.0.1 it is not yet fixed. In addition I noted that the task, submitted by "LocalSubmit" ,is not removed after it is finished. You have to call "TaskRemove" $\endgroup$ Jun 7, 2022 at 18:24
  • $\begingroup$ I got an answer from Wolfram confirming the answer from Roman: "I see this has been addressed by our developers on SE. Things are broken, but fixed in the next version to be released in the no too distant future." $\endgroup$ Jun 8, 2022 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.