Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: tools/dom/scripts/multiemitter.py

Issue 18676003: Make multiple attempts to write binding files to disc (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """Templating to help generate structured text.""" 6 """Templating to help generate structured text."""
7 7
8 import os 8 import os
9 import re
kustermann 2013/07/04 11:54:16 "re" was unused
10 import sys 9 import sys
11 import subprocess 10 import subprocess
11 import time
12 import emitter 12 import emitter
13 import logging 13 import logging
14 14
15 _logger = logging.getLogger('multiemitter') 15 _logger = logging.getLogger('multiemitter')
16 16
17 class MultiEmitter(object): 17 class MultiEmitter(object):
18 """A set of Emitters that write to different files. 18 """A set of Emitters that write to different files.
19 19
20 Each entry has a key. 20 Each entry has a key.
21 21
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 os.makedirs(dir) 78 os.makedirs(dir)
79 79
80 # Remove file if pre-existing. 80 # Remove file if pre-existing.
81 if os.path.exists(path): 81 if os.path.exists(path):
82 _logger.info('Removing - %s' % path) 82 _logger.info('Removing - %s' % path)
83 os.remove(path) 83 os.remove(path)
84 if os.path.exists(path): 84 if os.path.exists(path):
85 _logger.info('Warning: File still exists- %s' % path) 85 _logger.info('Warning: File still exists- %s' % path)
86 86
87 # Write the file. 87 # Write the file.
88 try: 88 num_attempts = 4
89 _logger.info('Writing - %s' % path) 89 for i in range(num_attempts):
90 f = open(path, 'w') 90 try:
91 f.writelines(lines) 91 _logger.info('Writing (attempt %d) - %s' % (i + 1, path))
92 f.close() 92 f = open(path, 'w')
93 except IOError as error: 93 f.writelines(lines)
94 # FIXME(kustermann): Remove this later on. 94 f.close()
95 # We try to get more debugging information to figure out why we sometimes 95 return
96 # get a "Permission denied" error when opening the file for writing. 96 except IOError as error:
97 # (hypothesis: Another process has already opened the file.) 97 last_attempt = (i == (num_attempts - 1))
98 _logger.info('Got exception (%s) ' % error) 98 if not last_attempt:
99 # Sleep for 50 ms and try again
100 time.sleep(0.05)
101 else:
102 # FIXME(kustermann): Remove this later on.
103 # We try to get more debugging information to figure out why we
104 # sometimes get a "Permission denied" error when opening the file for
105 # writing. (hypothesis: Another process has already opened the file.)
106 _logger.info('Got exception (%s) ' % error)
99 107
100 if sys.platform == 'win32': 108 if sys.platform == 'win32':
101 handle_file = r'E:\handle.exe' 109 handle_file = r'E:\handle.exe'
102 if os.path.exists(handle_file): 110 if os.path.exists(handle_file):
103 _logger.info('Running handle.exe for debugging purposes') 111 _logger.info('Running handle.exe for debugging purposes')
104 subprocess.call([handle_file, '-a', r'E:\b\build\slave']) 112 subprocess.call([handle_file, '-a', r'E:\b\build\slave'])
105 else: 113 else:
106 _logger.info("Couldn't find %s. Not printing open handles." 114 _logger.info("Couldn't find %s. Not printing open handles."
107 % handle_file) 115 % handle_file)
108 raise error 116 raise error
117
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698