Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tables_open_file func to retry opening #21

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ska_helpers/retry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
__all__ = ['retry', 'retry_call', 'RetryError']
__all__ = ['retry', 'retry_call', 'RetryError', 'tables_open_file']

import logging
from logging import StreamHandler

from .api import retry, retry_call, RetryError
from .api import retry, retry_call, RetryError, tables_open_file

log = logging.getLogger(__name__)
log.addHandler(StreamHandler())
22 changes: 22 additions & 0 deletions ska_helpers/retry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

logging_logger = logging.getLogger(__name__)


class RetryError(Exception):
"""
Keep track of the stack of exceptions when trying multiple times.
Expand Down Expand Up @@ -131,3 +132,24 @@ def retry_call(f, args=None, kwargs=None, exceptions=Exception, tries=-1, delay=

return __retry_internal(f, exceptions, tries, delay, max_delay,
backoff, jitter, logger, args=args, kwargs=kwargs)


def tables_open_file(*args, **kwargs):
"""Call tables.open_file(*args, **kwargs) with retry up to 3 times.

This only catches tables.exceptions.HDF5ExtError. After an initial failure
it will try again after 2 seconds and once more after 4 seconds.

:param *args: args passed through to tables.open_file()
:param **kwargs: kwargs passed through to tables.open_file()
:returns: tables file handle
"""
import ska_helpers.retry
import tables
import tables.exceptions

h5 = ska_helpers.retry.retry_call(
tables.open_file, args=args, kwargs=kwargs,
exceptions=tables.exceptions.HDF5ExtError,
delay=2, tries=3, backoff=2)
return h5
2 changes: 0 additions & 2 deletions ska_helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,3 @@ def cache_info():
_wrapped.cache_clear = func.cache_clear
return _wrapped
return _wrapper