##// END OF EJS Templates
tracing: ignore any IOErrors when writing to pipe...
Augie Fackler -
r39434:45279028 default
parent child Browse files
Show More
@@ -1,34 +1,44 b''
1 1 # Support code for event tracing in Mercurial. Lives in demandimport
2 2 # so it can also be used in demandimport.
3 3 #
4 4 # Copyright 2018 Google LLC.
5 5 #
6 6 # This software may be used and distributed according to the terms of the
7 7 # GNU General Public License version 2 or any later version.
8 8 from __future__ import absolute_import
9 9
10 10 import contextlib
11 11 import os
12 12
13 13 _pipe = None
14 14 _checked = False
15 15
16 16 @contextlib.contextmanager
17 17 def log(whencefmt, *whenceargs):
18 18 global _pipe, _session, _checked
19 19 if _pipe is None:
20 20 if _checked:
21 21 yield
22 22 return
23 23 _checked = True
24 24 if 'HGCATAPULTSERVERPIPE' not in os.environ:
25 25 yield
26 26 return
27 27 _pipe = open(os.environ['HGCATAPULTSERVERPIPE'], 'w', 1)
28 28 _session = os.environ.get('HGCATAPULTSESSION', 'none')
29 29 whence = whencefmt % whenceargs
30 30 try:
31 # Both writes to the pipe are wrapped in try/except to ignore
32 # errors, as we can see mysterious errors in here if the pager
33 # is active. Presumably other conditions could trigger
34 # problems too.
35 try:
31 36 _pipe.write('START %s %s\n' % (_session, whence))
37 except IOError:
38 pass
32 39 yield
33 40 finally:
41 try:
34 42 _pipe.write('END %s %s\n' % (_session, whence))
43 except IOError:
44 pass
General Comments 0
You need to be logged in to leave comments. Login now