Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
e771d57e
Unverified
Commit
e771d57e
authored
Nov 08, 2022
by
liuzhe-lz
Committed by
GitHub
Nov 08, 2022
Browse files
Catch broader exceptions in websocket reconnect (#5208)
parent
d7f33a73
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
nni/runtime/tuner_command_channel/channel.py
nni/runtime/tuner_command_channel/channel.py
+12
-5
No files found.
nni/runtime/tuner_command_channel/channel.py
View file @
e771d57e
...
@@ -60,7 +60,10 @@ class TunerCommandChannel:
...
@@ -60,7 +60,10 @@ class TunerCommandChannel:
command
=
command_type
.
value
.
decode
()
+
data
command
=
command_type
.
value
.
decode
()
+
data
try
:
try
:
self
.
_channel
.
send
(
command
)
self
.
_channel
.
send
(
command
)
except
WebSocket
.
ConnectionClosed
:
except
Exception
as
e
:
_logger
.
warning
(
'Exception on sending: %r'
,
e
)
if
not
isinstance
(
e
,
WebSocket
.
ConnectionClosed
):
_logger
.
exception
(
e
)
self
.
_retry_send
(
command
)
self
.
_retry_send
(
command
)
def
_retry_send
(
self
,
command
:
str
)
->
None
:
def
_retry_send
(
self
,
command
:
str
)
->
None
:
...
@@ -69,6 +72,7 @@ class TunerCommandChannel:
...
@@ -69,6 +72,7 @@ class TunerCommandChannel:
_logger
.
info
(
f
'Attempt #
{
i
}
, wait
{
interval
}
seconds...'
)
_logger
.
info
(
f
'Attempt #
{
i
}
, wait
{
interval
}
seconds...'
)
time
.
sleep
(
interval
)
time
.
sleep
(
interval
)
self
.
_channel
=
WebSocket
(
self
.
_url
)
self
.
_channel
=
WebSocket
(
self
.
_url
)
self
.
_channel
.
connect
()
try
:
try
:
self
.
_channel
.
send
(
command
)
self
.
_channel
.
send
(
command
)
_logger
.
info
(
'Reconnected.'
)
_logger
.
info
(
'Reconnected.'
)
...
@@ -81,9 +85,10 @@ class TunerCommandChannel:
...
@@ -81,9 +85,10 @@ class TunerCommandChannel:
def
_receive
(
self
)
->
tuple
[
CommandType
,
str
]
|
tuple
[
None
,
None
]:
def
_receive
(
self
)
->
tuple
[
CommandType
,
str
]
|
tuple
[
None
,
None
]:
try
:
try
:
command
=
self
.
_channel
.
receive
()
command
=
self
.
_channel
.
receive
()
except
WebSocket
.
ConnectionClosed
:
except
Exception
as
e
:
# this is for robustness and should never happen
_logger
.
warning
(
'Exception on receiving: %r'
,
e
)
_logger
.
warning
(
'ConnectionClosed exception on receiving.'
)
if
not
isinstance
(
e
,
WebSocket
.
ConnectionClosed
):
_logger
.
exception
(
e
)
command
=
None
command
=
None
if
command
is
None
:
if
command
is
None
:
command
=
self
.
_retry_receive
()
command
=
self
.
_retry_receive
()
...
@@ -96,9 +101,11 @@ class TunerCommandChannel:
...
@@ -96,9 +101,11 @@ class TunerCommandChannel:
_logger
.
info
(
f
'Attempt #
{
i
}
, wait
{
interval
}
seconds...'
)
_logger
.
info
(
f
'Attempt #
{
i
}
, wait
{
interval
}
seconds...'
)
time
.
sleep
(
interval
)
time
.
sleep
(
interval
)
self
.
_channel
=
WebSocket
(
self
.
_url
)
self
.
_channel
=
WebSocket
(
self
.
_url
)
self
.
_channel
.
connect
()
try
:
try
:
command
=
self
.
_channel
.
receive
()
command
=
self
.
_channel
.
receive
()
except
WebSocket
.
ConnectionClosed
:
except
Exception
as
e
:
_logger
.
exception
(
e
)
command
=
None
# for robustness
command
=
None
# for robustness
if
command
is
not
None
:
if
command
is
not
None
:
_logger
.
info
(
'Reconnected'
)
_logger
.
info
(
'Reconnected'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment