I believe there is a bug in TaskPaper’s file read/write code that causes deadlocks when other applications are also editing a file
Over the years I have periodically switched between TaskPaper and other approaches to organizing my life. I am currently in a TaskPaper phase. I keep my TaskPaper files inside folders that “live” inside nvUltra (a successor to nvAlt that Brett Terpstra and I are creating), and sometimes edit them in nvUltra, sometimes in TaskPaper, and sometimes both (depending on what I need to do.) . This generally works well, until it doesn’t…
In nvUltra (and MultiMarkdown Composer), I use Apple’s NSFileCoordinator to control access to reading/writing files and to “play nice” with the OS and other applications. Aside from the usual glitches during initial development, this has worked really well, and allows me to edit files in nvUltra while also working with them in other applications. Edits in one application appear in the the other, allowing me to use the best tool for whatever I am doing. The main tricks were properly handling multi-threading to handle it when changes were happening frequently.
I am frequently running into problems when editing a file in nvUltra and TaskPaper at the same time, however. If I edit a file in nvUltra and another app (for example, MultiMarkdown Composer), there are no issues. I can jump back and forth no problem, and make changes in either app. But when I open the file in TaskPaper, and edit in nvUltra, TP will frequently lock up, which then causes nvUltra to freeze since it is waiting for the NSFileCoordinator to complete read/write tasks. If I force quit TaskPaper, then nvUltra starts working again, and all is well. I can even replicate the same thing by opening a file in nvUltra/TP/MMDC simultaneously. All is well until TP freezes, then the file stops updating with my edits from nvUltra. Killing TP results in nvUltra/MMDC working properly again. If I do the same thing with only nvUltra/MMDC, then the problem does not occur.
I think the likelihood of the lockup occurring is related to how frequently the file is saved. nvUltra’s save frequency can be changed (with every keystroke, with every word, with every sentence, etc.) Composer relies more on manual saving or waiting for macOS’ automatic periodic saving to occur. The freezes happen much more often when I am editing in nvUltra as compared to MultiMarkdown Composer. If I manually trigger a save in Composer very frequently while typing, I can get TP to lock up more easily. But if the edits only occur on the default macOS schedule, I don’t notice problems (though my testing of this is limited.)
Of course it is possible there is a bug in my code somewhere. The fact that I cannot replicate this when I take TaskPaper out of the equation makes this less likely in my opinion, but it does not entirely exclude it. However, the frequency with which I experience this problem when using TP and the fact that I never see it with other applications is relatively strong evidence of a problem in TP’s read/write code in this situation.
I would love to see this resolved. I’m happy to help troubleshoot or provide support for a solution if you desire. Being able to safely work with a file even when while it is edited from another program is a great functionality that I make use of all the time, and it’s frustrating to have to stop what I am doing to force quit TaskPaper periodically when this happens.
Thanks!
Fletcher