mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
make fileserverclient.close fully robust
Test Plan: ran tests Reviewers: durham Reviewed By: durham Differential Revision: https://phabricator.fb.com/D2544243 Signature: t1:2544243:1444883084:a7b9cc9167a7671e34813826ba9fcd289919afd1
This commit is contained in:
parent
f8360b4766
commit
9943d04f51
@ -67,35 +67,31 @@ class cacheconnection(object):
|
||||
self.connected = True
|
||||
|
||||
def close(self):
|
||||
self.connected = False
|
||||
# if the process is still open, terminate it
|
||||
# close the pipes
|
||||
if self.pipei:
|
||||
def tryclose(pipe):
|
||||
try:
|
||||
pipe.close()
|
||||
except:
|
||||
pass
|
||||
if self.connected:
|
||||
try:
|
||||
self.pipei.write("exit\n")
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
self.pipei.close()
|
||||
finally:
|
||||
tryclose(self.pipei)
|
||||
self.pipei = None
|
||||
if self.pipeo:
|
||||
try:
|
||||
self.pipeo.close()
|
||||
finally:
|
||||
tryclose(self.pipeo)
|
||||
self.pipeo = None
|
||||
if self.pipee:
|
||||
try:
|
||||
self.pipee.close()
|
||||
finally:
|
||||
tryclose(self.pipee)
|
||||
self.pipee = None
|
||||
try:
|
||||
# Wait for process to terminate, making sure to avoid deadlock. See
|
||||
# https://docs.python.org/2/library/subprocess.html#popen-objects
|
||||
# for warnings about wait() and
|
||||
# Wait for process to terminate, making sure to avoid deadlock.
|
||||
# See https://docs.python.org/2/library/subprocess.html for
|
||||
# warnings about wait() and deadlocking.
|
||||
self.subprocess.communicate()
|
||||
finally:
|
||||
except:
|
||||
pass
|
||||
self.subprocess = None
|
||||
self.connected = False
|
||||
|
||||
def request(self, request, flush=True):
|
||||
if self.connected:
|
||||
|
Loading…
Reference in New Issue
Block a user