Skip to content

Commit

Permalink
Use 'with lock:' instead of acquire()/release()
Browse files Browse the repository at this point in the history
This could prevent deadlocks like #1, although not that specific one.
  • Loading branch information
mgedmin committed Apr 15, 2015
1 parent a7c1406 commit 7f82548
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/zdaemon/zdrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,17 +630,15 @@ def copy(self):
o = e = []
while 1:
ii, oo, ee = select.select(i, o, e)
lock.acquire()
for fd in ii:
self.write(os.read(fd, 8192))
lock.release()
with lock:
for fd in ii:
self.write(os.read(fd, 8192))

def reopen(self):
self.lock.acquire()
self.file.close()
self.file = open(self.filename, 'ab', 0)
self.write = self.file.write
self.lock.release()
with self.lock:
self.file.close()
self.file = open(self.filename, 'ab', 0)
self.write = self.file.write


# Helpers for dealing with signals and exit status
Expand Down

0 comments on commit 7f82548

Please sign in to comment.