@@ -132,16 +132,19 @@ def do_GET(self):
132
132
if "kernel" in (query := parse_qs (url .query )):
133
133
def getarg (k :str ,default = 0 ): return int (query [k ][0 ]) if k in query else default
134
134
kidx , ridx = getarg ("kernel" ), getarg ("idx" )
135
- # stream details
136
- self .send_response (200 )
137
- self .send_header ("Content-Type" , "text/event-stream" )
138
- self .send_header ("Cache-Control" , "no-cache" )
139
- self .end_headers ()
140
- for r in get_details (contexts [0 ][kidx ], contexts [1 ][kidx ][ridx ]):
141
- self .wfile .write (f"data: { json .dumps (r )} \n \n " .encode ("utf-8" ))
142
- self .wfile .flush ()
143
- self .wfile .write ("data: END\n \n " .encode ("utf-8" ))
144
- return self .wfile .flush ()
135
+ try :
136
+ # stream details
137
+ self .send_response (200 )
138
+ self .send_header ("Content-Type" , "text/event-stream" )
139
+ self .send_header ("Cache-Control" , "no-cache" )
140
+ self .end_headers ()
141
+ for r in get_details (contexts [0 ][kidx ], contexts [1 ][kidx ][ridx ]):
142
+ self .wfile .write (f"data: { json .dumps (r )} \n \n " .encode ("utf-8" ))
143
+ self .wfile .flush ()
144
+ self .wfile .write ("data: END\n \n " .encode ("utf-8" ))
145
+ return self .wfile .flush ()
146
+ # pass if client closed connection
147
+ except (BrokenPipeError , ConnectionResetError ): return
145
148
ret , content_type = json .dumps (kernels ).encode (), "application/json"
146
149
elif url .path == "/get_profile" and perfetto_profile is not None : ret , content_type = perfetto_profile , "application/json"
147
150
else : status_code = 404
0 commit comments