|
19 | 19 |
|
20 | 20 | import numpy as np |
21 | 21 | import tfs |
22 | | -from jpype import JException, java |
23 | 22 |
|
| 23 | +# from jpype import JException, java |
24 | 24 | from omc3.tune_analysis import constants as const |
25 | 25 | from omc3.utils import logging_tools |
26 | 26 | from omc3.utils.mock import cern_network_import |
|
32 | 32 |
|
33 | 33 | LOG = logging_tools.get_logger(__name__) |
34 | 34 | pytimber = cern_network_import("pytimber") |
| 35 | +jpype = cern_network_import("jpype") |
35 | 36 |
|
36 | 37 | MAX_RETRIES = 10 # number of retries on retryable exception |
37 | 38 | AcceptableTimeStamp = NewType("AcceptableTimeStamp", Union[CERNDatetime, int, float]) |
@@ -60,7 +61,7 @@ def extract_between_times( |
60 | 61 | t_start: AcceptableTimeStamp, |
61 | 62 | t_end: AcceptableTimeStamp, |
62 | 63 | keys: Sequence[str] = None, |
63 | | - names: Dict[str, str] = None |
| 64 | + names: Dict[str, str] = None, |
64 | 65 | ) -> tfs.TfsDataFrame: |
65 | 66 | """ |
66 | 67 | Extracts data for keys between ``t_start`` and ``t_end`` from ``Timber``. |
@@ -90,13 +91,15 @@ def extract_between_times( |
90 | 91 | try: |
91 | 92 | # We use timestamps to avoid any confusion with local time |
92 | 93 | extract_dict = db.get(keys, t_start.timestamp(), t_end.timestamp()) |
93 | | - except java.lang.IllegalStateException as e: |
94 | | - raise IOError("Could not get data from Timber, user probably has no access to NXCALS") from e |
95 | | - except JException as e: # Might be a case for retries |
96 | | - if "RetryableException" in str(e) and (tries + 1) < MAX_RETRIES: |
| 94 | + except jpype.java.lang.IllegalStateException as java_state_error: |
| 95 | + raise IOError( |
| 96 | + "Could not get data from Timber, user probably has no access to NXCALS" |
| 97 | + ) from java_state_error |
| 98 | + except jpype.JException as java_exception: # Might be a case for retries |
| 99 | + if "RetryableException" in str(java_exception) and (tries + 1) < MAX_RETRIES: |
97 | 100 | LOG.warning(f"Could not get data from Timber! Trial no {tries + 1} / {MAX_RETRIES}") |
98 | 101 | continue # will go to the next iteratoin of the loop, so retry |
99 | | - raise IOError("Could not get data from timber!") from e |
| 102 | + raise IOError("Could not get data from timber!") from java_exception |
100 | 103 | else: |
101 | 104 | break |
102 | 105 |
|
|
0 commit comments