@@ -22,7 +22,6 @@ import os
2222import uuid
2323import zmq .asyncio
2424import concurrent .futures
25- import Pyro4 .errors
2625import logging
2726import abc
2827import functools
@@ -33,6 +32,12 @@ import mtda.constants as CONSTS
3332from mtda .console .remote import RemoteConsole
3433from mtda .console .screen import ScreenOutput
3534
35+ # Pyro
36+ try :
37+ import Pyro5 .errors as PyroErrors
38+ except ImportError :
39+ import Pyro4 .errors as PyroErrors
40+
3641# ---------------------------------------------------------------------------
3742# Configure basic logging for better visibility of errors
3843# ---------------------------------------------------------------------------
@@ -102,10 +107,10 @@ class RemoteCallHandler(BaseHandler, metaclass=abc.ABCMeta):
102107 f"status={ status } response={ response } " )
103108
104109 self .set_status (status )
110+ # For 204 No Content, we just set status and finish, no body needed
105111 if response is not None :
106112 self .result_as_json (response )
107- # For 204 No Content, we just set status and finish, no body needed
108- except Pyro4 .errors .TimeoutError :
113+ except PyroErrors .TimeoutError :
109114 logger .warning ("Remote service timed out for "
110115 f"{ self .__class__ .__name__ } " )
111116 self .set_status (504 ) # Gateway Timeout
@@ -187,7 +192,7 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
187192 {"video-info" : {"format" : fmt , "url" : video_url }}
188193 )
189194
190- except Pyro4 . errors .TimeoutError :
195+ except PyroErrors .TimeoutError :
191196 logger .warning ("timeout during WebSocket for session "
192197 f"{ self .session_id } ." )
193198 self .write_message ({"error" : "timeout during WebSocket "
@@ -237,7 +242,7 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
237242 mtda .console_send , input_data ,
238243 raw = False , session = sid
239244 )
240- except Pyro4 . errors .TimeoutError :
245+ except PyroErrors .TimeoutError :
241246 logger .warning ("timeout for console_send "
242247 f"for session { sid } ." )
243248 self .write_message (
@@ -1138,7 +1143,7 @@ class OpenAPIHandler(tornado.web.RequestHandler):
11381143 }
11391144 }
11401145 self .write (spec )
1141- except Pyro4 . errors .TimeoutError :
1146+ except PyroErrors .TimeoutError :
11421147 logger .warning ("Pyro4 timeout fetching agent version for OpenAPI." )
11431148 self .set_status (504 )
11441149 self .write ({"error" : "timeout while fetching API version" })
0 commit comments