bpo-31234: Add support.join_thread() helper (#3587) · python/cpython@b9b6900

@@ -123,9 +123,7 @@ def line_terminator_check(self, term, server_chunk):

123123

c.push(b"I'm not dead yet!" + term)

124124

c.push(SERVER_QUIT)

125125

asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)

126-

s.join(timeout=TIMEOUT)

127-

if s.is_alive():

128-

self.fail("join() timed out")

126+

support.join_thread(s, timeout=TIMEOUT)

129127130128

self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])

131129

@@ -156,9 +154,7 @@ def numeric_terminator_check(self, termlen):

156154

c.push(data)

157155

c.push(SERVER_QUIT)

158156

asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)

159-

s.join(timeout=TIMEOUT)

160-

if s.is_alive():

161-

self.fail("join() timed out")

157+

support.join_thread(s, timeout=TIMEOUT)

162158163159

self.assertEqual(c.contents, [data[:termlen]])

164160

@@ -178,9 +174,7 @@ def test_none_terminator(self):

178174

c.push(data)

179175

c.push(SERVER_QUIT)

180176

asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)

181-

s.join(timeout=TIMEOUT)

182-

if s.is_alive():

183-

self.fail("join() timed out")

177+

support.join_thread(s, timeout=TIMEOUT)

184178185179

self.assertEqual(c.contents, [])

186180

self.assertEqual(c.buffer, data)

@@ -192,9 +186,7 @@ def test_simple_producer(self):

192186

p = asynchat.simple_producer(data+SERVER_QUIT, buffer_size=8)

193187

c.push_with_producer(p)

194188

asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)

195-

s.join(timeout=TIMEOUT)

196-

if s.is_alive():

197-

self.fail("join() timed out")

189+

support.join_thread(s, timeout=TIMEOUT)

198190199191

self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])

200192

@@ -204,9 +196,7 @@ def test_string_producer(self):

204196

data = b"hello world\nI'm not dead yet!\n"

205197

c.push_with_producer(data+SERVER_QUIT)

206198

asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)

207-

s.join(timeout=TIMEOUT)

208-

if s.is_alive():

209-

self.fail("join() timed out")

199+

support.join_thread(s, timeout=TIMEOUT)

210200211201

self.assertEqual(c.contents, [b"hello world", b"I'm not dead yet!"])

212202

@@ -217,9 +207,7 @@ def test_empty_line(self):

217207

c.push(b"hello world\n\nI'm not dead yet!\n")

218208

c.push(SERVER_QUIT)

219209

asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)

220-

s.join(timeout=TIMEOUT)

221-

if s.is_alive():

222-

self.fail("join() timed out")

210+

support.join_thread(s, timeout=TIMEOUT)

223211224212

self.assertEqual(c.contents,

225213

[b"hello world", b"", b"I'm not dead yet!"])

@@ -238,9 +226,7 @@ def test_close_when_done(self):

238226

# where the server echoes all of its data before we can check that it

239227

# got any down below.

240228

s.start_resend_event.set()

241-

s.join(timeout=TIMEOUT)

242-

if s.is_alive():

243-

self.fail("join() timed out")

229+

support.join_thread(s, timeout=TIMEOUT)

244230245231

self.assertEqual(c.contents, [])

246232

# the server might have been able to send a byte or two back, but this

@@ -261,7 +247,7 @@ def test_push(self):

261247

self.assertRaises(TypeError, c.push, 'unicode')

262248

c.push(SERVER_QUIT)

263249

asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)

264-

s.join(timeout=TIMEOUT)

250+

support.join_thread(s, timeout=TIMEOUT)

265251

self.assertEqual(c.contents, [b'bytes', b'bytes', b'bytes'])

266252267253