@@ -55,38 +55,44 @@ def seekable(self):
55
55
return False
56
56
57
57
def readinto (self , b , / ):
58
- while self ._chunk is None :
59
- if self ._queue .empty ():
60
- if self ._thread .is_alive ():
61
- time .sleep (0 )
62
- continue
63
- else :
64
- # EOF
65
- return 0
66
- chunk = self ._queue .get ()
67
- if chunk :
68
- self ._chunk = chunk
69
-
70
- if len (self ._chunk ) <= len (b ):
71
- bytes_written = len (self ._chunk )
72
- b [:bytes_written ] = self ._chunk
73
- self ._chunk = None
58
+ try :
59
+ while self ._chunk is None :
60
+ if self ._queue .empty ():
61
+ if self ._thread .is_alive ():
62
+ time .sleep (0 )
63
+ continue
64
+ else :
65
+ # EOF
66
+ return 0
67
+ chunk = self ._queue .get ()
68
+ if chunk :
69
+ self ._chunk = chunk
70
+
71
+ if len (self ._chunk ) <= len (b ):
72
+ bytes_written = len (self ._chunk )
73
+ b [:bytes_written ] = self ._chunk
74
+ self ._chunk = None
75
+ return bytes_written
76
+ bytes_written = len (b )
77
+ b [:] = self ._chunk [:bytes_written ]
78
+ self ._chunk = self ._chunk [bytes_written :]
74
79
return bytes_written
75
- bytes_written = len (b )
76
- b [:] = self ._chunk [:bytes_written ]
77
- self ._chunk = self ._chunk [bytes_written :]
78
- return bytes_written
80
+ except KeyboardInterrupt :
81
+ return 0
79
82
80
83
def close (self ):
81
- while True :
82
- if self ._queue .empty ():
83
- if self ._thread .is_alive ():
84
- time .sleep (0 )
84
+ try :
85
+ while True :
86
+ if self ._queue .empty ():
87
+ if self ._thread .is_alive ():
88
+ time .sleep (0 )
89
+ else :
90
+ break
85
91
else :
86
- break
87
- else :
88
- self . _queue . get ()
89
- self . _thread . join ()
92
+ self . _queue . get ()
93
+ self . _thread . join ()
94
+ except KeyboardInterrupt :
95
+ pass
90
96
91
97
92
98
class BlobIO (io .BufferedReader , AbstractContextManager ):
0 commit comments