[Inteproxy-commits] r25 - trunk

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Feb 8 13:35:09 CET 2007


Author: bh
Date: 2007-02-08 13:35:08 +0100 (Thu, 08 Feb 2007)
New Revision: 25

Modified:
   trunk/ChangeLog
   trunk/InteProxy.py
   trunk/getpassword.py
Log:
* InteProxy.py (run_server): New option --workers to specify the
number of the worker threads.  Default is 5.  run_server now
starts the requested number of threads.
 
* getpassword.py (get_password_with_cache): Access the password
cache in a thread-safe way.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-02-08 12:07:08 UTC (rev 24)
+++ trunk/ChangeLog	2007-02-08 12:35:08 UTC (rev 25)
@@ -1,5 +1,14 @@
 2007-02-08  Bernhard Herzog  <bh at intevation.de>
 
+	* InteProxy.py (run_server): New option --workers to specify the
+	number of the worker threads.  Default is 5.  run_server now
+	starts the requested number of threads.
+ 
+	* getpassword.py (get_password_with_cache): Access the password
+	cache in a thread-safe way.
+
+2007-02-08  Bernhard Herzog  <bh at intevation.de>
+
 	* test/runtests.py, test/test_owsproxy_post_transcoder.py,
 	test/test_owsproxy_get_transcoder.py: New files with the
 	beginnings of a test suite.

Modified: trunk/InteProxy.py
===================================================================
--- trunk/InteProxy.py	2007-02-08 12:07:08 UTC (rev 24)
+++ trunk/InteProxy.py	2007-02-08 12:35:08 UTC (rev 25)
@@ -337,10 +337,11 @@
                ServerClass = MasterWorkerServer):
     """Run the InteProxy server"""
     parser = optparse.OptionParser()
-    parser.set_defaults(port=64609)
+    parser.set_defaults(port=64609, workers=5)
     parser.add_option("--logfile")
     parser.add_option("--allow-shutdown", action="store_true")
     parser.add_option("--port", type="int")
+    parser.add_option("--workers", type="int")
     parser.add_option("--debug-level", type="int")
     opts, rest = parser.parse_args()
 
@@ -359,10 +360,12 @@
 
     httpd = ServerClass(server_address, HandlerClass)
 
-    sys.stderr.write("[%s] starting worker thread\n" % log_date_time_string())
-    worker = threading.Thread(target = worker_thread)
-    worker.setDaemon(1)
-    worker.start()
+    sys.stderr.write("[%s] starting %d worker threads\n" \
+                     % (log_date_time_string(), opts.workers))
+    for i in range(opts.workers):
+        worker = threading.Thread(target = worker_thread)
+        worker.setDaemon(1)
+        worker.start()
 
     print "Serving HTTP on port", opts.port, "..."
     sys.stderr.write("[%s] serving HTTP on port %d\n"

Modified: trunk/getpassword.py
===================================================================
--- trunk/getpassword.py	2007-02-08 12:07:08 UTC (rev 24)
+++ trunk/getpassword.py	2007-02-08 12:35:08 UTC (rev 25)
@@ -7,6 +7,7 @@
 
 """Code to ask the user for username and password"""
 
+import threading
 import traceback
 
 # Determine the window system we're using.  This determines how the user
@@ -33,8 +34,9 @@
 
 getpassword = globals()["getpassword_" + windowsystem]
 
-# password cache
+# password cache and lock
 pw_cache = {}
+pw_lock = threading.Lock()
 
 def get_password_with_cache(path):
     """Ask the user for a username and password and cache the
@@ -47,11 +49,15 @@
 
     The return value is the tuple (username, password).
     """
-    if path in pw_cache:
-        user, password = pw_cache[path]
-    else:
-        title = "Username for %s: " % path
-        user, password = getpassword(title)
-        pw_cache[path] = user, password
+    pw_lock.acquire()
+    try:
+        if path in pw_cache:
+            user, password = pw_cache[path]
+        else:
+            title = "Username for %s: " % path
+            user, password = getpassword(title)
+            pw_cache[path] = user, password
 
-    return user, password
+        return user, password
+    finally:
+        pw_lock.release()



More information about the Inteproxy-commits mailing list