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
5f412905
Commit
5f412905
authored
Dec 20, 2023
by
BO ZHANG
🏀
Browse files
add retry
parent
fc788084
Pipeline
#2594
running with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
csst_common/utils/__init__.py
View file @
5f412905
...
...
@@ -10,4 +10,8 @@ Modified-History:
"""
from
._module_docstr
import
ModuleHeader
from
._retry
import
retry
from
.tempfile
import
randfile
csst_common/utils/_retry.py
0 → 100644
View file @
5f412905
"""
Identifier: csst_common/utils/_retry.py
Name: _retry.py
Description: CSST utils
Author: Bo Zhang
Created: 2023-12-20
Modified-History:
2023-12-20, Bo Zhang, add retry
"""
def
retry
(
func
,
n_try
=
3
,
*
args
,
**
kwargs
):
# is DFS?
try
:
assert
func
.
__self__
.
__class__
.
__module__
.
startswith
(
"csst_dfs_api"
),
func
is_dfs
=
True
except
BaseException
:
is_dfs
=
False
# start trials
for
attempt
in
range
(
n_try
):
print
(
f
"Trial #
{
attempt
}
: call
{
func
}
"
)
try
:
res
=
func
(
*
args
,
**
kwargs
)
if
is_dfs
:
assert
res
[
"code"
]
==
0
,
res
return
res
except
BaseException
as
e
:
print
(
f
"Error occurs:
{
e
.
__repr__
()
}
"
)
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