[tor-commits] [bridgedb/master] Change pidfile writer to use with(open()).

isis at torproject.org isis at torproject.org
Sun Jan 12 06:06:32 UTC 2014


commit 1fa9c4965975766260d3d1e34b60f5627cfb6874
Author: Isis Lovecruft <isis at torproject.org>
Date:   Fri Nov 15 14:35:43 2013 +0000

    Change pidfile writer to use with(open()).
---
 lib/bridgedb/Main.py |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py
index 0b1512a..0c984c0 100644
--- a/lib/bridgedb/Main.py
+++ b/lib/bridgedb/Main.py
@@ -339,9 +339,10 @@ def startup(options, rundir, configFile):
     # the real PIDFILE would get overwritten with the PID of the temporary
     # bridgedb process running the subcommand.
     if config.PIDFILE:
-        f = open(config.PIDFILE, 'w')
-        f.write("%s\n" % os.getpid())
-        f.close()
+        logging.debug("Writing server PID to file: '%s'" % config.PIDFILE)
+        with open(config.PIDFILE, 'w') as pidfile:
+            pidfile.write("%s\n" % os.getpid())
+            pidfile.flush()
 
     # Import Servers after logging is set up. Otherwise, python will create a
     # default handler that logs to the console and ignore further basicConfig





More information about the tor-commits mailing list