
Hi Cafe. There's good news and there's bad news. The bad news is... I'm back. [Did I miss anything good?] The good news is... I have an actual question to ask as well. When I write to a file using System.IO, the file is locked for exclusive access. I gather this is as specified in the Haskell Report. Which is nice, but... I'd actually prefer the file to *not* be locked. Anybody know how to do that?

andrewcoppin:
Hi Cafe.
There's good news and there's bad news.
The bad news is... I'm back. [Did I miss anything good?]
The good news is... I have an actual question to ask as well.
When I write to a file using System.IO, the file is locked for exclusive access. I gather this is as specified in the Haskell Report. Which is nice, but... I'd actually prefer the file to *not* be locked. Anybody know how to do that?
Hey Andrew, What are you trying to do? Read and write to the same file (if so, you need to use strict IO), or are you trying something sneakier? -- Don

Don Stewart wrote:
Hey Andrew,
What are you trying to do? Read and write to the same file (if so, you need to use strict IO), or are you trying something sneakier?
I have a long-running Haskell program that writes status information to a log file. I'd like to be able to open and read that log file before the program has actually terminated. I have a similar program written in Tcl that allows me to do this, since apparently the Tcl interpretter doesn't lock output files for exclusive access. Haskell, however, does. (This seems to be the stipulated behaviour as per the Report.) If there's an easy way to change this, it would be useful...

andrewcoppin:
Don Stewart wrote:
Hey Andrew,
What are you trying to do? Read and write to the same file (if so, you need to use strict IO), or are you trying something sneakier?
I have a long-running Haskell program that writes status information to a log file. I'd like to be able to open and read that log file before the program has actually terminated. I have a similar program written in Tcl that allows me to do this, since apparently the Tcl interpretter doesn't lock output files for exclusive access. Haskell, however, does. (This seems to be the stipulated behaviour as per the Report.) If there's an easy way to change this, it would be useful...
Did you open the file in ReadWriteMode ? -- Don

Don Stewart wrote:
andrewcoppin:
Don Stewart wrote:
Hey Andrew,
What are you trying to do? Read and write to the same file (if so, you need to use strict IO), or are you trying something sneakier?
I have a long-running Haskell program that writes status information to a log file. I'd like to be able to open and read that log file before the program has actually terminated. I have a similar program written in Tcl that allows me to do this, since apparently the Tcl interpretter doesn't lock output files for exclusive access. Haskell, however, does. (This seems to be the stipulated behaviour as per the Report.) If there's an easy way to change this, it would be useful...
Did you open the file in ReadWriteMode ?
Nope. Just WriteMode. I'm trying to read the file from Notepad.exe while my Haskell program is still running - which takes about an hour.

andrewcoppin:
Nope. Just WriteMode. I'm trying to read the file from Notepad.exe while my Haskell program is still running - which takes about an hour.
Oh, you want another process in the system to read the file while GHC is writing to it? This works fine on unix systems -- and perhaps Neil, or one of the other windows experts, can explain what the story is on Windows. -- Don

Don Stewart wrote:
Oh, you want another process in the system to read the file while GHC is writing to it?
That's the one. ;-) [Well, not GHC but my GHC-compiled binary, but anyway...]
This works fine on unix systems -- and perhaps Neil, or one of the other windows experts, can explain what the story is on Windows.
I thought the Report... wait, let me check... Oh, OK, that's not what I thought the Report says. Section 21.2.3, "File Locking". I thought it says that Haskell is supposed to prevent access to the same file by multiple threads. (And that, presumably, is why it's using an exclusive lock to try to implement these semantics under the Win32 API.) However, that's apparently not what it says... (It says multiple reader / single writer.) So... does this count as a bug then?

On Mar 12, 2008, at 4:07 PM, Andrew Coppin wrote:
I'm trying to read the file from Notepad.exe while my Haskell program is still running - which takes about an hour.
I'm not a Windows user, but... Is it possible that Notepad tries to write-lock by default (since it's an editor), and fails? Put another way, have you tried other ways of reading the file? Heck, copying the file should be a read-only action. Can you copy it during the runtime, and open the copy? -johnnnnnnn

John Melesky wrote:
On Mar 12, 2008, at 4:07 PM, Andrew Coppin wrote:
I'm trying to read the file from Notepad.exe while my Haskell program is still running - which takes about an hour.
I'm not a Windows user, but... Is it possible that Notepad tries to write-lock by default (since it's an editor), and fails?
Notepad successfully opens the log file of another script I'm running, so that's not the issue.

On Wed, Mar 12, 2008 at 10:03 PM, Andrew Coppin
Don Stewart wrote:
Hey Andrew,
What are you trying to do? Read and write to the same file (if so, you need to use strict IO), or are you trying something sneakier?
I have a long-running Haskell program that writes status information to a log file. I'd like to be able to open and read that log file before the program has actually terminated. I have a similar program written in Tcl that allows me to do this, since apparently the Tcl interpretter doesn't lock output files for exclusive access. Haskell, however, does. (This seems to be the stipulated behaviour as per the Report.) If there's an easy way to change this, it would be useful...
How about using appendFile? "appendFile :: FilePath -> String -> IO () The computation appendFile file str function appends the string str, to the file file." See http://haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#v%3Aap... /Björn

Andrew Coppin wrote:
Don Stewart wrote:
Hey Andrew,
What are you trying to do? Read and write to the same file (if so, you need to use strict IO), or are you trying something sneakier?
I have a long-running Haskell program that writes status information to a log file. I'd like to be able to open and read that log file before the program has actually terminated. I have a similar program written in Tcl that allows me to do this, since apparently the Tcl interpretter doesn't lock output files for exclusive access. Haskell, however, does. (This seems to be the stipulated behaviour as per the Report.) If there's an easy way to change this, it would be useful...
AIUI, and I could be wrong: The haskell report mandates locking. On win32, this locking is implemented using win32 (mandatory) locking primitives, and thus it affects other processes. On unix, this locking is implementing using an advisory/optional locking system which is only noticed by other haskell threads. (On many versions of unix, at least historically, there was no mandatory locking; mandatory locking is an anathema to unix programmers) Thus, the problem you have is win32 specific and requires access to the Win32 primitive to resolve, as I understand it. There are probably primitives in Win32 packages for this? Or you could use appendfile instead, Jules

Hello Andrew, Wednesday, March 12, 2008, 10:06:44 PM, you wrote:
When I write to a file using System.IO, the file is locked for exclusive access. I gather this is as specified in the Haskell Report. Which is nice, but... I'd actually prefer the file to *not* be locked. Anybody know how to do that?
one (and only?) possible way is to use Streams library which happens to not lock files: http://haskell.org/haskellwiki/Library/Streams -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (6)
-
Andrew Coppin
-
Bjorn Bringert
-
Bulat Ziganshin
-
Don Stewart
-
John Melesky
-
Jules Bean