Skip to content

Commit 51636f7

Browse files
committed
asyncio.CancelledError is BaseException now, so fix except Exception
1 parent 0bb811d commit 51636f7

File tree

7 files changed

+117
-39
lines changed

7 files changed

+117
-39
lines changed

uvloop/_testbase.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,9 @@ def __init__(self, test, sock, prog, timeout):
415415
def run(self):
416416
try:
417417
self._prog(TestSocketWrapper(self._sock))
418-
except Exception as ex:
418+
except (KeyboardInterrupt, SystemExit):
419+
raise
420+
except BaseException as ex:
419421
self._test._abort_socket_test(ex)
420422

421423

@@ -485,7 +487,9 @@ def _run(self):
485487
try:
486488
with conn:
487489
self._handle_client(conn)
488-
except Exception as ex:
490+
except (KeyboardInterrupt, SystemExit):
491+
raise
492+
except BaseException as ex:
489493
self._active = False
490494
try:
491495
raise

uvloop/cbhandles.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ cdef class Handle:
8686
raise RuntimeError('invalid Handle.cb_type: {}'.format(
8787
cb_type))
8888

89-
except Exception as ex:
89+
except (KeyboardInterrupt, SystemExit):
90+
raise
91+
except BaseException as ex:
9092
if cb_type == 1:
9193
msg = 'Exception in callback {}'.format(callback)
9294
else:
@@ -263,7 +265,9 @@ cdef class TimerHandle:
263265
callback(*args)
264266
else:
265267
callback()
266-
except Exception as ex:
268+
except (KeyboardInterrupt, SystemExit):
269+
raise
270+
except BaseException as ex:
267271
context = {
268272
'message': 'Exception in callback {}'.format(callback),
269273
'exception': ex,

uvloop/dns.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ cdef void __on_addrinfo_resolved(uv.uv_getaddrinfo_t *resolver,
386386
ai = AddrInfo()
387387
ai.set_data(res)
388388
callback(ai)
389-
except Exception as ex:
389+
except (KeyboardInterrupt, SystemExit):
390+
raise
391+
except BaseException as ex:
390392
loop._handle_exception(ex)
391393
finally:
392394
request.on_done()
@@ -407,7 +409,9 @@ cdef void __on_nameinfo_resolved(uv.uv_getnameinfo_t* req,
407409
else:
408410
callback(((<bytes>hostname).decode(),
409411
(<bytes>service).decode()))
410-
except Exception as ex:
412+
except (KeyboardInterrupt, SystemExit):
413+
raise
414+
except BaseException as ex:
411415
loop._handle_exception(ex)
412416
finally:
413417
request.on_done()

uvloop/handles/basetransport.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ cdef class UVBaseTransport(UVSocketHandle):
6767
self._protocol_paused = 1
6868
try:
6969
self._protocol.pause_writing()
70-
except Exception as exc:
70+
except (KeyboardInterrupt, SystemExit):
71+
raise
72+
except BaseException as exc:
7173
self._loop.call_exception_handler({
7274
'message': 'protocol.pause_writing() failed',
7375
'exception': exc,
@@ -83,7 +85,9 @@ cdef class UVBaseTransport(UVSocketHandle):
8385
self._protocol_paused = 0
8486
try:
8587
self._protocol.resume_writing()
86-
except Exception as exc:
88+
except (KeyboardInterrupt, SystemExit):
89+
raise
90+
except BaseException as exc:
8791
self._loop.call_exception_handler({
8892
'message': 'protocol.resume_writing() failed',
8993
'exception': exc,

uvloop/handles/process.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,9 @@ cdef class UVProcessTransport(UVProcess):
521521
cdef _call_connection_made(self, waiter):
522522
try:
523523
self._protocol.connection_made(self)
524-
except Exception as ex:
524+
except (KeyboardInterrupt, SystemExit):
525+
raise
526+
except BaseException as ex:
525527
if waiter is not None and not waiter.cancelled():
526528
waiter.set_exception(ex)
527529
else:

uvloop/loop.pyx

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,9 @@ cdef class Loop:
854854
data = result
855855
else:
856856
data = (<AddrInfo>result).unpack()
857-
except Exception as ex:
857+
except (KeyboardInterrupt, SystemExit):
858+
raise
859+
except BaseException as ex:
858860
if not fut.cancelled():
859861
fut.set_exception(ex)
860862
else:
@@ -899,7 +901,9 @@ cdef class Loop:
899901
# No need to re-add the reader, let's just wait until
900902
# the poll handler calls this callback again.
901903
pass
902-
except Exception as exc:
904+
except (KeyboardInterrupt, SystemExit):
905+
raise
906+
except BaseException as exc:
903907
fut.set_exception(exc)
904908
self._remove_reader(sock)
905909
else:
@@ -924,7 +928,9 @@ cdef class Loop:
924928
# No need to re-add the reader, let's just wait until
925929
# the poll handler calls this callback again.
926930
pass
927-
except Exception as exc:
931+
except (KeyboardInterrupt, SystemExit):
932+
raise
933+
except BaseException as exc:
928934
fut.set_exception(exc)
929935
self._remove_reader(sock)
930936
else:
@@ -952,7 +958,9 @@ cdef class Loop:
952958
except (BlockingIOError, InterruptedError):
953959
# Try next time.
954960
return
955-
except Exception as exc:
961+
except (KeyboardInterrupt, SystemExit):
962+
raise
963+
except BaseException as exc:
956964
fut.set_exception(exc)
957965
self._remove_writer(sock)
958966
return
@@ -984,7 +992,9 @@ cdef class Loop:
984992
# There is an active reader for _sock_accept, so
985993
# do nothing, it will be called again.
986994
pass
987-
except Exception as exc:
995+
except (KeyboardInterrupt, SystemExit):
996+
raise
997+
except BaseException as exc:
988998
fut.set_exception(exc)
989999
self._remove_reader(sock)
9901000
else:
@@ -1027,7 +1037,9 @@ cdef class Loop:
10271037
except (BlockingIOError, InterruptedError):
10281038
# socket is still registered, the callback will be retried later
10291039
pass
1030-
except Exception as exc:
1040+
except (KeyboardInterrupt, SystemExit):
1041+
raise
1042+
except BaseException as exc:
10311043
fut.set_exception(exc)
10321044
else:
10331045
fut.set_result(None)
@@ -1528,7 +1540,9 @@ cdef class Loop:
15281540

15291541
try:
15301542
await waiter
1531-
except Exception:
1543+
except (KeyboardInterrupt, SystemExit):
1544+
raise
1545+
except BaseException:
15321546
app_transport.close()
15331547
conmade_cb.cancel()
15341548
resume_cb.cancel()
@@ -1695,7 +1709,9 @@ cdef class Loop:
16951709

16961710
try:
16971711
tcp._open(sock.fileno())
1698-
except Exception:
1712+
except (KeyboardInterrupt, SystemExit):
1713+
raise
1714+
except BaseException:
16991715
tcp._close()
17001716
raise
17011717

@@ -1729,7 +1745,9 @@ cdef class Loop:
17291745

17301746
try:
17311747
tcp._open(sock.fileno())
1732-
except Exception:
1748+
except (KeyboardInterrupt, SystemExit):
1749+
raise
1750+
except BaseException:
17331751
tcp._close()
17341752
raise
17351753

@@ -1910,7 +1928,9 @@ cdef class Loop:
19101928
tr._close()
19111929
tr = None
19121930
exceptions.append(exc)
1913-
except Exception:
1931+
except (KeyboardInterrupt, SystemExit):
1932+
raise
1933+
except BaseException:
19141934
if tr is not None:
19151935
tr._close()
19161936
tr = None
@@ -1948,7 +1968,9 @@ cdef class Loop:
19481968
tr._open(sock.fileno())
19491969
tr._init_protocol()
19501970
await waiter
1951-
except Exception:
1971+
except (KeyboardInterrupt, SystemExit):
1972+
raise
1973+
except BaseException:
19521974
# It's OK to call `_close()` here, as opposed to
19531975
# `_force_close()` or `close()` as we want to terminate the
19541976
# transport immediately. The `waiter` can only be waken
@@ -1963,7 +1985,9 @@ cdef class Loop:
19631985
app_transport = protocol._get_app_transport()
19641986
try:
19651987
await ssl_waiter
1966-
except Exception:
1988+
except (KeyboardInterrupt, SystemExit):
1989+
raise
1990+
except BaseException:
19671991
app_transport.close()
19681992
raise
19691993
return app_transport, app_protocol
@@ -2064,7 +2088,9 @@ cdef class Loop:
20642088
raise OSError(errno.EADDRINUSE, msg) from None
20652089
else:
20662090
raise
2067-
except Exception:
2091+
except (KeyboardInterrupt, SystemExit):
2092+
raise
2093+
except BaseException:
20682094
sock.close()
20692095
raise
20702096

@@ -2088,7 +2114,9 @@ cdef class Loop:
20882114

20892115
try:
20902116
pipe._open(sock.fileno())
2091-
except Exception:
2117+
except (KeyboardInterrupt, SystemExit):
2118+
raise
2119+
except BaseException:
20922120
pipe._close()
20932121
sock.close()
20942122
raise
@@ -2161,7 +2189,9 @@ cdef class Loop:
21612189
tr.connect(path)
21622190
try:
21632191
await waiter
2164-
except Exception:
2192+
except (KeyboardInterrupt, SystemExit):
2193+
raise
2194+
except BaseException:
21652195
tr._close()
21662196
raise
21672197

@@ -2184,7 +2214,9 @@ cdef class Loop:
21842214
tr._open(sock.fileno())
21852215
tr._init_protocol()
21862216
await waiter
2187-
except Exception:
2217+
except (KeyboardInterrupt, SystemExit):
2218+
raise
2219+
except BaseException:
21882220
tr._close()
21892221
raise
21902222

@@ -2194,7 +2226,9 @@ cdef class Loop:
21942226
app_transport = protocol._get_app_transport()
21952227
try:
21962228
await ssl_waiter
2197-
except Exception:
2229+
except (KeyboardInterrupt, SystemExit):
2230+
raise
2231+
except BaseException:
21982232
app_transport.close()
21992233
raise
22002234
return app_transport, app_protocol
@@ -2233,7 +2267,9 @@ cdef class Loop:
22332267
else:
22342268
try:
22352269
value = repr(value)
2236-
except Exception as ex:
2270+
except (KeyboardInterrupt, SystemExit):
2271+
raise
2272+
except BaseException as ex:
22372273
value = ('Exception in __repr__ {!r}; '
22382274
'value type: {!r}'.format(ex, type(value)))
22392275
log_lines.append('{}: {}'.format(key, value))
@@ -2287,7 +2323,9 @@ cdef class Loop:
22872323
if self._exception_handler is None:
22882324
try:
22892325
self.default_exception_handler(context)
2290-
except Exception:
2326+
except (KeyboardInterrupt, SystemExit):
2327+
raise
2328+
except BaseException:
22912329
# Second protection layer for unexpected errors
22922330
# in the default implementation, as well as for subclassed
22932331
# event loops with overloaded "default_exception_handler".
@@ -2296,7 +2334,9 @@ cdef class Loop:
22962334
else:
22972335
try:
22982336
self._exception_handler(self, context)
2299-
except Exception as exc:
2337+
except (KeyboardInterrupt, SystemExit):
2338+
raise
2339+
except BaseException as exc:
23002340
# Exception in the user set custom exception handler.
23012341
try:
23022342
# Let's try default handler.
@@ -2305,7 +2345,9 @@ cdef class Loop:
23052345
'exception': exc,
23062346
'context': context,
23072347
})
2308-
except Exception:
2348+
except (KeyboardInterrupt, SystemExit):
2349+
raise
2350+
except BaseException:
23092351
# Guard 'default_exception_handler' in case it is
23102352
# overloaded.
23112353
aio_logger.error('Exception in default exception handler '
@@ -2558,14 +2600,18 @@ cdef class Loop:
25582600
app_transport = protocol._get_app_transport()
25592601
try:
25602602
await waiter
2561-
except Exception:
2603+
except (KeyboardInterrupt, SystemExit):
2604+
raise
2605+
except BaseException:
25622606
app_transport.close()
25632607
raise
25642608
return app_transport, protocol
25652609
else:
25662610
try:
25672611
await waiter
2568-
except Exception:
2612+
except (KeyboardInterrupt, SystemExit):
2613+
raise
2614+
except BaseException:
25692615
transport._close()
25702616
raise
25712617
return transport, protocol
@@ -2641,7 +2687,9 @@ cdef class Loop:
26412687

26422688
try:
26432689
await waiter
2644-
except Exception:
2690+
except (KeyboardInterrupt, SystemExit):
2691+
raise
2692+
except BaseException:
26452693
proc.close()
26462694
raise
26472695

@@ -2693,7 +2741,9 @@ cdef class Loop:
26932741
transp._open(pipe.fileno())
26942742
transp._init_protocol()
26952743
await waiter
2696-
except Exception:
2744+
except (KeyboardInterrupt, SystemExit):
2745+
raise
2746+
except BaseException:
26972747
transp._close()
26982748
raise
26992749
transp._attach_fileobj(pipe)
@@ -2718,7 +2768,9 @@ cdef class Loop:
27182768
transp._open(pipe.fileno())
27192769
transp._init_protocol()
27202770
await waiter
2721-
except Exception:
2771+
except (KeyboardInterrupt, SystemExit):
2772+
raise
2773+
except BaseException:
27222774
transp._close()
27232775
raise
27242776
transp._attach_fileobj(pipe)
@@ -2948,7 +3000,9 @@ cdef class Loop:
29483000
if reuse_port:
29493001
self._sock_set_reuseport(udp._fileno())
29503002
udp._bind(lai.ai_addr, reuse_address)
2951-
except Exception as ex:
3003+
except (KeyboardInterrupt, SystemExit):
3004+
raise
3005+
except BaseException as ex:
29523006
lai = lai.ai_next
29533007
excs.append(ex)
29543008
continue

0 commit comments

Comments
 (0)