safe simultaneous file append?

Donn Cave donn at u.washington.edu
Mon Oct 8 12:20:23 EDT 2001


Quoth "Chris Gonnerman" <chris.gonnerman at newcenturycomputers.net>:
... [ re O_APPEND ]

| The only thing you need to do for safety is to ensure that complete
| messages are written by a single write(2) call.  Do this:
|
|     logfile.write("A long message...\n")
|
| rather than this:
|
|     logfile.write("A ")
|     logfile.write("long message...")
|     logfile.write("\n")
|
| (for instance)
|
| It wouldn't hurt to add
|
|     logfile.flush()
|
| after each write.

In fact that flush() would be a darn good idea. Or just use posix.write
directly, to get that single write(2) call.  Otherwise, if you just let
the file object do its thing, I'm pretty sure the appended write will be
a buffer and not a line.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list