Even in a toy web application like the Picky Picky Game, it is possible (but unlikely) that two people will want to upload a picture at (nearly) the exact same moment. If two processes try to write the same file at the same time, the results could be a mess. It follows that we need to include something to co-ordinate the changes.

If this application were all running as a single-process, multi-threaded web server (as ZOPE does), then this would be easily done with ZODB, but, alas! I am still stubbornly trying to implement this as a CGI script, and ZODB cannot co-ordinate transactions between different processes.

I thought that ZEO might fix this—it manages a ZODB database that can be shared between many servers, which should make it more than adequate for monitoring separate processes on the same server. And everything works fine when I run test scripts at the command line, but, at first it failed when the script is invoked as a CGI.

At this point I was wondering what to try next—stop using CGI (write my sever using Python’s own HTTPServer module, or as a Twisted application, or ...), write my own co-ordination server, etc. Then it occurred to me that my ZEO instance was bound to a Unix-domain socket, and since CGI runs using the nobody uid, it could not connect to that socket (because of file-system permissions). So I tried switching to using a TCP socket instead, and it works! Yay!

17 November 2002

Article Archive by Year