@@ -854,7 +854,9 @@ cdef class Loop:
854
854
data = result
855
855
else :
856
856
data = (< AddrInfo> result).unpack()
857
- except Exception as ex:
857
+ except (KeyboardInterrupt , SystemExit ):
858
+ raise
859
+ except BaseException as ex:
858
860
if not fut.cancelled():
859
861
fut.set_exception(ex)
860
862
else :
@@ -899,7 +901,9 @@ cdef class Loop:
899
901
# No need to re-add the reader, let's just wait until
900
902
# the poll handler calls this callback again.
901
903
pass
902
- except Exception as exc:
904
+ except (KeyboardInterrupt , SystemExit ):
905
+ raise
906
+ except BaseException as exc:
903
907
fut.set_exception(exc)
904
908
self ._remove_reader(sock)
905
909
else :
@@ -924,7 +928,9 @@ cdef class Loop:
924
928
# No need to re-add the reader, let's just wait until
925
929
# the poll handler calls this callback again.
926
930
pass
927
- except Exception as exc:
931
+ except (KeyboardInterrupt , SystemExit ):
932
+ raise
933
+ except BaseException as exc:
928
934
fut.set_exception(exc)
929
935
self ._remove_reader(sock)
930
936
else :
@@ -952,7 +958,9 @@ cdef class Loop:
952
958
except (BlockingIOError, InterruptedError):
953
959
# Try next time.
954
960
return
955
- except Exception as exc:
961
+ except (KeyboardInterrupt , SystemExit ):
962
+ raise
963
+ except BaseException as exc:
956
964
fut.set_exception(exc)
957
965
self ._remove_writer(sock)
958
966
return
@@ -984,7 +992,9 @@ cdef class Loop:
984
992
# There is an active reader for _sock_accept, so
985
993
# do nothing, it will be called again.
986
994
pass
987
- except Exception as exc:
995
+ except (KeyboardInterrupt , SystemExit ):
996
+ raise
997
+ except BaseException as exc:
988
998
fut.set_exception(exc)
989
999
self ._remove_reader(sock)
990
1000
else :
@@ -1027,7 +1037,9 @@ cdef class Loop:
1027
1037
except (BlockingIOError, InterruptedError):
1028
1038
# socket is still registered, the callback will be retried later
1029
1039
pass
1030
- except Exception as exc:
1040
+ except (KeyboardInterrupt , SystemExit ):
1041
+ raise
1042
+ except BaseException as exc:
1031
1043
fut.set_exception(exc)
1032
1044
else :
1033
1045
fut.set_result(None )
@@ -1528,7 +1540,9 @@ cdef class Loop:
1528
1540
1529
1541
try :
1530
1542
await waiter
1531
- except Exception :
1543
+ except (KeyboardInterrupt , SystemExit ):
1544
+ raise
1545
+ except BaseException :
1532
1546
app_transport.close()
1533
1547
conmade_cb.cancel()
1534
1548
resume_cb.cancel()
@@ -1695,7 +1709,9 @@ cdef class Loop:
1695
1709
1696
1710
try :
1697
1711
tcp._open(sock.fileno())
1698
- except Exception :
1712
+ except (KeyboardInterrupt , SystemExit ):
1713
+ raise
1714
+ except BaseException :
1699
1715
tcp._close()
1700
1716
raise
1701
1717
@@ -1729,7 +1745,9 @@ cdef class Loop:
1729
1745
1730
1746
try :
1731
1747
tcp._open(sock.fileno())
1732
- except Exception :
1748
+ except (KeyboardInterrupt , SystemExit ):
1749
+ raise
1750
+ except BaseException :
1733
1751
tcp._close()
1734
1752
raise
1735
1753
@@ -1910,7 +1928,9 @@ cdef class Loop:
1910
1928
tr._close()
1911
1929
tr = None
1912
1930
exceptions.append(exc)
1913
- except Exception :
1931
+ except (KeyboardInterrupt , SystemExit ):
1932
+ raise
1933
+ except BaseException :
1914
1934
if tr is not None :
1915
1935
tr._close()
1916
1936
tr = None
@@ -1948,7 +1968,9 @@ cdef class Loop:
1948
1968
tr._open(sock.fileno())
1949
1969
tr._init_protocol()
1950
1970
await waiter
1951
- except Exception :
1971
+ except (KeyboardInterrupt , SystemExit ):
1972
+ raise
1973
+ except BaseException :
1952
1974
# It's OK to call `_close()` here, as opposed to
1953
1975
# `_force_close()` or `close()` as we want to terminate the
1954
1976
# transport immediately. The `waiter` can only be waken
@@ -1963,7 +1985,9 @@ cdef class Loop:
1963
1985
app_transport = protocol._get_app_transport()
1964
1986
try :
1965
1987
await ssl_waiter
1966
- except Exception :
1988
+ except (KeyboardInterrupt , SystemExit ):
1989
+ raise
1990
+ except BaseException :
1967
1991
app_transport.close()
1968
1992
raise
1969
1993
return app_transport, app_protocol
@@ -2064,7 +2088,9 @@ cdef class Loop:
2064
2088
raise OSError (errno.EADDRINUSE, msg) from None
2065
2089
else :
2066
2090
raise
2067
- except Exception :
2091
+ except (KeyboardInterrupt , SystemExit ):
2092
+ raise
2093
+ except BaseException :
2068
2094
sock.close()
2069
2095
raise
2070
2096
@@ -2088,7 +2114,9 @@ cdef class Loop:
2088
2114
2089
2115
try :
2090
2116
pipe._open(sock.fileno())
2091
- except Exception :
2117
+ except (KeyboardInterrupt , SystemExit ):
2118
+ raise
2119
+ except BaseException :
2092
2120
pipe._close()
2093
2121
sock.close()
2094
2122
raise
@@ -2161,7 +2189,9 @@ cdef class Loop:
2161
2189
tr.connect(path)
2162
2190
try :
2163
2191
await waiter
2164
- except Exception :
2192
+ except (KeyboardInterrupt , SystemExit ):
2193
+ raise
2194
+ except BaseException :
2165
2195
tr._close()
2166
2196
raise
2167
2197
@@ -2184,7 +2214,9 @@ cdef class Loop:
2184
2214
tr._open(sock.fileno())
2185
2215
tr._init_protocol()
2186
2216
await waiter
2187
- except Exception :
2217
+ except (KeyboardInterrupt , SystemExit ):
2218
+ raise
2219
+ except BaseException :
2188
2220
tr._close()
2189
2221
raise
2190
2222
@@ -2194,7 +2226,9 @@ cdef class Loop:
2194
2226
app_transport = protocol._get_app_transport()
2195
2227
try :
2196
2228
await ssl_waiter
2197
- except Exception :
2229
+ except (KeyboardInterrupt , SystemExit ):
2230
+ raise
2231
+ except BaseException :
2198
2232
app_transport.close()
2199
2233
raise
2200
2234
return app_transport, app_protocol
@@ -2233,7 +2267,9 @@ cdef class Loop:
2233
2267
else :
2234
2268
try :
2235
2269
value = repr (value)
2236
- except Exception as ex:
2270
+ except (KeyboardInterrupt , SystemExit ):
2271
+ raise
2272
+ except BaseException as ex:
2237
2273
value = (' Exception in __repr__ {!r}; '
2238
2274
' value type: {!r}' .format(ex, type (value)))
2239
2275
log_lines.append(' {}: {}' .format(key, value))
@@ -2287,7 +2323,9 @@ cdef class Loop:
2287
2323
if self ._exception_handler is None :
2288
2324
try :
2289
2325
self .default_exception_handler(context)
2290
- except Exception :
2326
+ except (KeyboardInterrupt , SystemExit ):
2327
+ raise
2328
+ except BaseException :
2291
2329
# Second protection layer for unexpected errors
2292
2330
# in the default implementation, as well as for subclassed
2293
2331
# event loops with overloaded "default_exception_handler".
@@ -2296,7 +2334,9 @@ cdef class Loop:
2296
2334
else :
2297
2335
try :
2298
2336
self ._exception_handler(self , context)
2299
- except Exception as exc:
2337
+ except (KeyboardInterrupt , SystemExit ):
2338
+ raise
2339
+ except BaseException as exc:
2300
2340
# Exception in the user set custom exception handler.
2301
2341
try :
2302
2342
# Let's try default handler.
@@ -2305,7 +2345,9 @@ cdef class Loop:
2305
2345
' exception' : exc,
2306
2346
' context' : context,
2307
2347
})
2308
- except Exception :
2348
+ except (KeyboardInterrupt , SystemExit ):
2349
+ raise
2350
+ except BaseException :
2309
2351
# Guard 'default_exception_handler' in case it is
2310
2352
# overloaded.
2311
2353
aio_logger.error(' Exception in default exception handler '
@@ -2558,14 +2600,18 @@ cdef class Loop:
2558
2600
app_transport = protocol._get_app_transport()
2559
2601
try :
2560
2602
await waiter
2561
- except Exception :
2603
+ except (KeyboardInterrupt , SystemExit ):
2604
+ raise
2605
+ except BaseException :
2562
2606
app_transport.close()
2563
2607
raise
2564
2608
return app_transport, protocol
2565
2609
else :
2566
2610
try :
2567
2611
await waiter
2568
- except Exception :
2612
+ except (KeyboardInterrupt , SystemExit ):
2613
+ raise
2614
+ except BaseException :
2569
2615
transport._close()
2570
2616
raise
2571
2617
return transport, protocol
@@ -2641,7 +2687,9 @@ cdef class Loop:
2641
2687
2642
2688
try :
2643
2689
await waiter
2644
- except Exception :
2690
+ except (KeyboardInterrupt , SystemExit ):
2691
+ raise
2692
+ except BaseException :
2645
2693
proc.close()
2646
2694
raise
2647
2695
@@ -2693,7 +2741,9 @@ cdef class Loop:
2693
2741
transp._open(pipe.fileno())
2694
2742
transp._init_protocol()
2695
2743
await waiter
2696
- except Exception :
2744
+ except (KeyboardInterrupt , SystemExit ):
2745
+ raise
2746
+ except BaseException :
2697
2747
transp._close()
2698
2748
raise
2699
2749
transp._attach_fileobj(pipe)
@@ -2718,7 +2768,9 @@ cdef class Loop:
2718
2768
transp._open(pipe.fileno())
2719
2769
transp._init_protocol()
2720
2770
await waiter
2721
- except Exception :
2771
+ except (KeyboardInterrupt , SystemExit ):
2772
+ raise
2773
+ except BaseException :
2722
2774
transp._close()
2723
2775
raise
2724
2776
transp._attach_fileobj(pipe)
@@ -2948,7 +3000,9 @@ cdef class Loop:
2948
3000
if reuse_port:
2949
3001
self ._sock_set_reuseport(udp._fileno())
2950
3002
udp._bind(lai.ai_addr, reuse_address)
2951
- except Exception as ex:
3003
+ except (KeyboardInterrupt , SystemExit ):
3004
+ raise
3005
+ except BaseException as ex:
2952
3006
lai = lai.ai_next
2953
3007
excs.append(ex)
2954
3008
continue
0 commit comments