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

Unified Diff: build/android/pylib/device/device_blacklist.py

Issue 434193002: [Android] Parallelize provision_devices.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/device_settings.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/device_blacklist.py
diff --git a/build/android/pylib/device/device_blacklist.py b/build/android/pylib/device/device_blacklist.py
index b2124a74fac663a43b5ae6f1b1e1ddb7b2b7c55c..a141d62b81b828f17a243dbb70adbe8772ddba30 100644
--- a/build/android/pylib/device/device_blacklist.py
+++ b/build/android/pylib/device/device_blacklist.py
@@ -4,6 +4,7 @@
import json
import os
+import threading
from pylib import constants
_BLACKLIST_JSON = os.path.join(
@@ -11,17 +12,22 @@ _BLACKLIST_JSON = os.path.join(
os.environ.get('CHROMIUM_OUT_DIR', 'out'),
'bad_devices.json')
+# Note that this only protects against concurrent accesses to the blacklist
+# within a process.
+_blacklist_lock = threading.RLock()
+
def ReadBlacklist():
"""Reads the blacklist from the _BLACKLIST_JSON file.
Returns:
A list containing bad devices.
"""
- if not os.path.exists(_BLACKLIST_JSON):
- return []
+ with _blacklist_lock:
+ if not os.path.exists(_BLACKLIST_JSON):
+ return []
- with open(_BLACKLIST_JSON, 'r') as f:
- return json.load(f)
+ with open(_BLACKLIST_JSON, 'r') as f:
+ return json.load(f)
def WriteBlacklist(blacklist):
@@ -30,8 +36,9 @@ def WriteBlacklist(blacklist):
Args:
blacklist: list of bad devices to write to the _BLACKLIST_JSON file.
"""
- with open(_BLACKLIST_JSON, 'w') as f:
- json.dump(list(set(blacklist)), f)
+ with _blacklist_lock:
+ with open(_BLACKLIST_JSON, 'w') as f:
+ json.dump(list(set(blacklist)), f)
def ExtendBlacklist(devices):
@@ -40,13 +47,15 @@ def ExtendBlacklist(devices):
Args:
devices: list of bad devices to be added to the _BLACKLIST_JSON file.
"""
- blacklist = ReadBlacklist()
- blacklist.extend(devices)
- WriteBlacklist(blacklist)
+ with _blacklist_lock:
+ blacklist = ReadBlacklist()
+ blacklist.extend(devices)
+ WriteBlacklist(blacklist)
def ResetBlacklist():
"""Erases the _BLACKLIST_JSON file if it exists."""
- if os.path.exists(_BLACKLIST_JSON):
- os.remove(_BLACKLIST_JSON)
+ with _blacklist_lock:
+ if os.path.exists(_BLACKLIST_JSON):
+ os.remove(_BLACKLIST_JSON)
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/device_settings.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698