Discussion:
Question about shared resources and thread safety
Steve Willis
2014-03-10 20:01:24 UTC
Permalink
I'm trying to track down a possible bug in my bottle-based application. I
am using the default wsgiref to serve web pages with forms to a small
collection of local computers (1-2 at a time). When form data is POSTed
back to the server, I open and read a plain text file, update that data
with the new form field data, and write the file back to disk, all within
the bottle POST handler. My understanding is that the wsgiref backend is
single-threaded, and I am therefore not performing any kind of explicit
locking on the text file that is read then written during the POST handler.
If it is of interest, I am using Python's ConfigParser module for the file
itself. My data storage needs are minimal, and sqlite would be both
overkill and would remove the human-readable aspect of the collected data.

After months of this setup working very well, I have encountered a single
possibly corrupt text file. I want to exclude the possibility that this
occurred due to multiple simultaneous POST requests. Am I correct that wsgi
ref can only handle one such request at a time, synchronously?

Thanks for your help, and for an excellent framework.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ron Rothman
2014-03-12 14:04:02 UTC
Permalink
If you're using wsgiref, and if you only have one server process running,
then no, you don't need to worry about locking. (Presumably, no other
processes (GUI tools, etc.) write to this file.)

[FWIW, a better (safer) approach might be to write to a temp file, and then
atomically rename that file to the original name. That way, your worst
case a lost update, but never a corrupt file (from interleaved updates).
IMO it's a good return on just a few lines of code.]
Post by Steve Willis
I'm trying to track down a possible bug in my bottle-based application. I
am using the default wsgiref to serve web pages with forms to a small
collection of local computers (1-2 at a time). When form data is POSTed
back to the server, I open and read a plain text file, update that data
with the new form field data, and write the file back to disk, all within
the bottle POST handler. My understanding is that the wsgiref backend is
single-threaded, and I am therefore not performing any kind of explicit
locking on the text file that is read then written during the POST handler.
If it is of interest, I am using Python's ConfigParser module for the file
itself. My data storage needs are minimal, and sqlite would be both
overkill and would remove the human-readable aspect of the collected data.
After months of this setup working very well, I have encountered a single
possibly corrupt text file. I want to exclude the possibility that this
occurred due to multiple simultaneous POST requests. Am I correct that wsgi
ref can only handle one such request at a time, synchronously?
Thanks for your help, and for an excellent framework.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...