Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-pipeline
csst_common
Commits
794846ae
Commit
794846ae
authored
Dec 18, 2025
by
BO ZHANG
🏀
Browse files
rewrite retry
parent
1ad1b00c
Pipeline
#11553
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
csst_common/utils/_retry.py
View file @
794846ae
...
...
@@ -8,6 +8,7 @@ Modified-History:
2023-12-20, Bo Zhang, add retry
"""
import
traceback
def
retry
(
func
,
*
args
,
**
kwargs
):
if
"n_try"
in
kwargs
.
keys
():
...
...
@@ -15,11 +16,7 @@ def retry(func, *args, **kwargs):
else
:
n_try
=
5
# is DFS?
try
:
assert
func
.
__self__
.
__class__
.
__module__
.
startswith
(
"csst_dfs_api"
),
func
is_dfs
=
True
except
BaseException
:
is_dfs
=
False
is_dfs
=
func
.
__self__
.
__class__
.
__module__
.
startswith
(
"csst_dfs_client"
)
# start trials
for
attempt
in
range
(
n_try
):
print
(
f
"Trial #
{
attempt
}
: call
{
func
}
"
)
...
...
@@ -28,9 +25,19 @@ def retry(func, *args, **kwargs):
if
is_dfs
:
assert
res
[
"code"
]
==
0
,
res
return
res
except
BaseException
as
e
:
print
(
f
"Error occurs:
{
e
.
__repr__
()
}
"
)
print
(
f
" - func:
{
func
}
"
)
print
(
f
" - args:
{
args
}
"
)
print
(
f
" - kwargs:
{
kwargs
}
"
)
except
Exception
as
e
:
# print error messages
print
(
f
"Error occurs in trial
{
attempt
+
1
}
/
{
n_try
}
:"
)
print
(
f
" - Error type:
{
type
(
e
).
__name__
}
"
)
print
(
f
" - Error message:
{
str
(
e
)
}
"
)
print
(
f
" - Function:
{
func
}
"
)
print
(
f
" - Args:
{
args
}
"
)
print
(
f
" - Kwargs:
{
kwargs
}
"
)
# 打印完整的堆栈跟踪
print
(
" - Stack trace:"
)
traceback
.
print_exc
()
if
attempt
==
n_try
-
1
:
print
(
f
"All
{
n_try
}
attempts failed. Reraising exception..."
)
raise
raise
RuntimeError
(
f
"All
{
n_try
}
attempts failed."
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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