Merge ~cjwatson/launchpad:new-threading-api into launchpad:master

Proposed by Colin Watson on 2019-10-11
Status: Merged
Approved by: Colin Watson on 2019-10-11
Approved revision: 2bb65fc80c8cd267b3f2723a4ad344ae90038cdb
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:new-threading-api
Merge into: launchpad:master
Diff against target: 281 lines (+27/-27)
16 files modified
bzrplugins/lpserve/__init__.py (+1/-1)
bzrplugins/lpserve/test_lpserve.py (+4/-4)
lib/lp/bugs/scripts/checkwatches/core.py (+4/-4)
lib/lp/bugs/scripts/checkwatches/tests/test_core.py (+1/-1)
lib/lp/codehosting/codeimport/tests/servers.py (+1/-1)
lib/lp/scripts/garbo.py (+2/-2)
lib/lp/services/database/doc/storm-store-reset.txt (+1/-1)
lib/lp/services/gpg/tests/test_gpghandler.py (+1/-1)
lib/lp/services/profile/mem.py (+1/-1)
lib/lp/services/profile/profile.py (+1/-1)
lib/lp/services/scripts/__init__.py (+1/-1)
lib/lp/services/timeout.py (+2/-2)
lib/lp/services/webapp/adapter.py (+1/-1)
lib/lp/services/webapp/publication.py (+1/-1)
lib/lp/services/webapp/sigusr1.py (+3/-3)
lib/lp/testing/layers.py (+2/-2)
Reviewer Review Type Date Requested Status
Tom Wardill 2019-10-11 Approve on 2019-10-11
Review via email: mp+374028@code.launchpad.net

Commit message

Use Python 2.6's new threading API

This involves some changes to use properties instead of accessor
methods, and some changes from camelCase to snake_case.

To post a comment you must log in.
Tom Wardill (twom) wrote :

Changes look good to me, have run tests, tests pass.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bzrplugins/lpserve/__init__.py b/bzrplugins/lpserve/__init__.py
2index 5ea5f86..1db2554 100644
3--- a/bzrplugins/lpserve/__init__.py
4+++ b/bzrplugins/lpserve/__init__.py
5@@ -627,7 +627,7 @@ class LPForkingService(object):
6 trace.note('Exiting')
7
8 def _do_loop(self):
9- while not self._should_terminate.isSet():
10+ while not self._should_terminate.is_set():
11 try:
12 conn, client_addr = self._server_socket.accept()
13 except self._socket_timeout:
14diff --git a/bzrplugins/lpserve/test_lpserve.py b/bzrplugins/lpserve/test_lpserve.py
15index fd5baa7..6879ee6 100644
16--- a/bzrplugins/lpserve/test_lpserve.py
17+++ b/bzrplugins/lpserve/test_lpserve.py
18@@ -95,10 +95,10 @@ class TestingLPForkingServiceInAThread(lpserve.LPForkingService):
19 thread = threading.Thread(target=new_service.main_loop,
20 name='TestingLPForkingServiceInAThread')
21 new_service.this_thread = thread
22- # should we be doing thread.setDaemon(True) ?
23+ # should we be doing thread.daemon = True ?
24 thread.start()
25 new_service.service_started.wait(10.0)
26- if not new_service.service_started.isSet():
27+ if not new_service.service_started.is_set():
28 raise RuntimeError(
29 'Failed to start the TestingLPForkingServiceInAThread')
30 test.addCleanup(new_service.stop_service)
31@@ -112,7 +112,7 @@ class TestingLPForkingServiceInAThread(lpserve.LPForkingService):
32 return
33 self._should_terminate.set()
34 self.service_stopped.wait(10.0)
35- if not self.service_stopped.isSet():
36+ if not self.service_stopped.is_set():
37 raise RuntimeError(
38 'Failed to stop the TestingLPForkingServiceInAThread')
39 self.this_thread.join()
40@@ -213,7 +213,7 @@ class TestLPForkingService(TestCaseWithLPForkingService):
41 response = self.send_message_to_service('quit\n')
42 self.assertEqual('ok\nquit command requested... exiting\n', response)
43 self.service.service_stopped.wait(10.0)
44- self.assertTrue(self.service.service_stopped.isSet())
45+ self.assertTrue(self.service.service_stopped.is_set())
46
47 def test_send_invalid_message_fails(self):
48 response = self.send_message_to_service('unknown\n')
49diff --git a/lib/lp/bugs/scripts/checkwatches/core.py b/lib/lp/bugs/scripts/checkwatches/core.py
50index 66e2d1f..5d47b6e 100644
51--- a/lib/lp/bugs/scripts/checkwatches/core.py
52+++ b/lib/lp/bugs/scripts/checkwatches/core.py
53@@ -174,15 +174,15 @@ class CheckwatchesMaster(WorkingBase):
54 def make_updater(bug_tracker_name, bug_tracker_id):
55 """Returns a function that can update the given bug tracker."""
56 def updater(batch_size=None):
57- thread = threading.currentThread()
58- thread_name = thread.getName()
59- thread.setName(bug_tracker_name)
60+ thread = threading.current_thread()
61+ thread_name = thread.name
62+ thread.name = bug_tracker_name
63 try:
64 with self.statement_logging:
65 return self.updateBugTracker(
66 bug_tracker_id, batch_size)
67 finally:
68- thread.setName(thread_name)
69+ thread.name = thread_name
70 return updater
71
72 for bug_tracker_name in bug_tracker_names:
73diff --git a/lib/lp/bugs/scripts/checkwatches/tests/test_core.py b/lib/lp/bugs/scripts/checkwatches/tests/test_core.py
74index b7fea39..f92f606 100644
75--- a/lib/lp/bugs/scripts/checkwatches/tests/test_core.py
76+++ b/lib/lp/bugs/scripts/checkwatches/tests/test_core.py
77@@ -410,7 +410,7 @@ class OutputFileForThreads:
78 self.lock = threading.Lock()
79
80 def write(self, data):
81- thread_name = threading.currentThread().getName()
82+ thread_name = threading.current_thread().name
83 with self.lock:
84 if thread_name in self.output:
85 self.output[thread_name].append(data)
86diff --git a/lib/lp/codehosting/codeimport/tests/servers.py b/lib/lp/codehosting/codeimport/tests/servers.py
87index 1b911d9..20388fc 100644
88--- a/lib/lp/codehosting/codeimport/tests/servers.py
89+++ b/lib/lp/codehosting/codeimport/tests/servers.py
90@@ -300,7 +300,7 @@ class HTTPGitServerThread(threading.Thread):
91
92 def __init__(self, backend, address, port=None):
93 super(HTTPGitServerThread, self).__init__()
94- self.setName("HTTP Git server on %s:%s" % (address, port))
95+ self.name = "HTTP Git server on %s:%s" % (address, port)
96 app = HTTPGitApplication(
97 backend,
98 handlers={'turnip-set-symbolic-ref': TurnipSetSymbolicRefHandler})
99diff --git a/lib/lp/scripts/garbo.py b/lib/lp/scripts/garbo.py
100index 1795f5a..b6b5f27 100644
101--- a/lib/lp/scripts/garbo.py
102+++ b/lib/lp/scripts/garbo.py
103@@ -1762,7 +1762,7 @@ class BaseDatabaseGarbageCollector(LaunchpadCronScript):
104 has timed out.
105 """
106 self.logger.debug(
107- "Worker thread %s running.", threading.currentThread().name)
108+ "Worker thread %s running.", threading.current_thread().name)
109 install_feature_controller(make_script_feature_controller(self.name))
110 self.login()
111
112@@ -1772,7 +1772,7 @@ class BaseDatabaseGarbageCollector(LaunchpadCronScript):
113 # Exit silently. We warn later.
114 self.logger.debug(
115 "Worker thread %s detected script timeout.",
116- threading.currentThread().name)
117+ threading.current_thread().name)
118 break
119
120 try:
121diff --git a/lib/lp/services/database/doc/storm-store-reset.txt b/lib/lp/services/database/doc/storm-store-reset.txt
122index d462f80..990f9c1 100644
123--- a/lib/lp/services/database/doc/storm-store-reset.txt
124+++ b/lib/lp/services/database/doc/storm-store-reset.txt
125@@ -23,7 +23,7 @@ we rely on that to find out whether or not to reset stores.
126 >>> def request_salgados_homepage():
127 ... global alive_items
128 ... global thread_name
129- ... thread_name = threading.currentThread().getName()
130+ ... thread_name = threading.current_thread().name
131 ... from lp.testing.pages import setupBrowser
132 ... http = setupBrowser(auth="Basic foo.bar@canonical.com:test")
133 ... http.open("http://launchpad.test/~salgado/+edit")
134diff --git a/lib/lp/services/gpg/tests/test_gpghandler.py b/lib/lp/services/gpg/tests/test_gpghandler.py
135index a818cf0..ca24c3b 100644
136--- a/lib/lp/services/gpg/tests/test_gpghandler.py
137+++ b/lib/lp/services/gpg/tests/test_gpghandler.py
138@@ -166,7 +166,7 @@ class TestGPGHandler(TestCase):
139 # raises GPGKeyTemporarilyNotFoundError.
140 # We simulate a timeout using responses rather than by setting a low
141 # timeout, as otherwise the test will fail if the fetch thread
142- # happens to complete between Thread.start and Thread.isAlive.
143+ # happens to complete between Thread.start and Thread.is_alive.
144 responses.add(
145 'GET',
146 self.gpg_handler.getURLForKeyInServer(
147diff --git a/lib/lp/services/profile/mem.py b/lib/lp/services/profile/mem.py
148index 67ce8d1..19bc988 100644
149--- a/lib/lp/services/profile/mem.py
150+++ b/lib/lp/services/profile/mem.py
151@@ -210,7 +210,7 @@ def logInThread(n=30):
152 reflog = file('/tmp/refs.log', 'w')
153 t = threading.Thread(target=_logRefsEverySecond, args=(reflog, n))
154 # Allow process to exit without explicitly stopping thread.
155- t.setDaemon(True)
156+ t.daemon = True
157 t.start()
158
159
160diff --git a/lib/lp/services/profile/profile.py b/lib/lp/services/profile/profile.py
161index 8a89c57..7516045 100644
162--- a/lib/lp/services/profile/profile.py
163+++ b/lib/lp/services/profile/profile.py
164@@ -321,7 +321,7 @@ def end_request(event):
165 oops_report = request.oops
166 filename = '%s-%s-%s-%s' % (
167 timestamp, pageid, oopsid,
168- threading.currentThread().getName())
169+ threading.current_thread().name)
170 if 'callgrind' in actions:
171 # The stats class looks at the filename to know to use
172 # callgrind syntax.
173diff --git a/lib/lp/services/scripts/__init__.py b/lib/lp/services/scripts/__init__.py
174index f8eeb42..51456c2 100644
175--- a/lib/lp/services/scripts/__init__.py
176+++ b/lib/lp/services/scripts/__init__.py
177@@ -101,7 +101,7 @@ def execute_zcml_for_scripts(use_web_security=False):
178 thread, zope.sendmail.delivery.QueueProcessorThread):
179 thread.stop()
180 thread.join(30)
181- if thread.isAlive():
182+ if thread.is_alive():
183 raise RuntimeError(
184 "QueueProcessorThread did not shut down")
185 atexit.register(kill_queue_processor_threads)
186diff --git a/lib/lp/services/timeout.py b/lib/lp/services/timeout.py
187index 1c77d37..d96456f 100644
188--- a/lib/lp/services/timeout.py
189+++ b/lib/lp/services/timeout.py
190@@ -232,10 +232,10 @@ class with_timeout:
191 # This will commonly be SoftTimeLimitExceeded from celery,
192 # since celery's timeout often happens before the job's due
193 # to job setup time.
194- if t.isAlive():
195+ if t.is_alive():
196 cleanup(t, args)
197 raise
198- if t.isAlive():
199+ if t.is_alive():
200 cleanup(t, args)
201 raise TimeoutError("timeout exceeded.")
202 if getattr(t, 'exc_info', None) is not None:
203diff --git a/lib/lp/services/webapp/adapter.py b/lib/lp/services/webapp/adapter.py
204index 08a22c4..e4cfcc3 100644
205--- a/lib/lp/services/webapp/adapter.py
206+++ b/lib/lp/services/webapp/adapter.py
207@@ -710,7 +710,7 @@ class LaunchpadStatementTracer:
208 sys.stderr.write("." * 70 + "\n")
209 # store the last executed statement as an attribute on the current
210 # thread
211- threading.currentThread().lp_last_sql_statement = statement
212+ threading.current_thread().lp_last_sql_statement = statement
213 request_starttime = getattr(_local, 'request_start_time', None)
214 if request_starttime is None:
215 if print_traceback or self._debug_sql or log_sql is not None:
216diff --git a/lib/lp/services/webapp/publication.py b/lib/lp/services/webapp/publication.py
217index 1b01f53..ece870a 100644
218--- a/lib/lp/services/webapp/publication.py
219+++ b/lib/lp/services/webapp/publication.py
220@@ -768,7 +768,7 @@ class LaunchpadBrowserPublication(
221 OpStats.stats['5XXs_b'] += 1
222
223 # Make sure our databases are in a sane state for the next request.
224- thread_name = threading.currentThread().getName()
225+ thread_name = threading.current_thread().name
226 for name, store in getUtility(IZStorm).iterstores():
227 try:
228 assert store._connection._state != STATE_DISCONNECTED, (
229diff --git a/lib/lp/services/webapp/sigusr1.py b/lib/lp/services/webapp/sigusr1.py
230index 07ec112..1ef7c80 100644
231--- a/lib/lp/services/webapp/sigusr1.py
232+++ b/lib/lp/services/webapp/sigusr1.py
233@@ -21,7 +21,7 @@ def sigusr1_handler(signum, frame):
234 # isn't an appserver thread.
235 if not hasattr(thread, 'lp_last_request'):
236 continue
237- message.append('\t%s' % thread.getName())
238+ message.append('\t%s' % thread.name)
239 message.append('\t\tLast Request: %s' % thread.lp_last_request)
240 message.append('\t\tMost recent OOPS IDs: %s' %
241 ', '.join(getattr(thread, 'lp_last_oops', [])))
242@@ -38,7 +38,7 @@ def setup_sigusr1(event):
243 def before_traverse(event):
244 """Record the request URL (provided that the request has a URL)"""
245 request = event.request
246- threading.currentThread().lp_last_request = str(
247+ threading.current_thread().lp_last_request = str(
248 getattr(request, 'URL', ''))
249
250
251@@ -46,7 +46,7 @@ def end_request(event):
252 """Record the OOPS ID in the thread, if one occurred."""
253 request = event.request
254 if request.oopsid is not None:
255- thread = threading.currentThread()
256+ thread = threading.current_thread()
257 last_oops_ids = getattr(thread, 'lp_last_oops', [])
258 # make sure the OOPS ID list has at most 5 elements
259 thread.lp_last_oops = last_oops_ids[-4:] + [request.oopsid]
260diff --git a/lib/lp/testing/layers.py b/lib/lp/testing/layers.py
261index 647fbb1..0f00f62 100644
262--- a/lib/lp/testing/layers.py
263+++ b/lib/lp/testing/layers.py
264@@ -421,7 +421,7 @@ class BaseLayer:
265 def new_live_threads():
266 return [
267 thread for thread in threading.enumerate()
268- if thread not in BaseLayer._threads and thread.isAlive()]
269+ if thread not in BaseLayer._threads and thread.is_alive()]
270
271 if BaseLayer.disable_thread_check:
272 new_threads = None
273@@ -434,7 +434,7 @@ class BaseLayer:
274 has_live_threads = False
275 for new_thread in new_threads:
276 new_thread.join(0.1)
277- if new_thread.isAlive():
278+ if new_thread.is_alive():
279 has_live_threads = True
280 if has_live_threads:
281 # Trigger full garbage collection that might be

Subscribers

People subscribed via source and target branches