diff --git a/jina/clients/base/grpc.py b/jina/clients/base/grpc.py index 917950d05c4fd..06958d0d41762 100644 --- a/jina/clients/base/grpc.py +++ b/jina/clients/base/grpc.py @@ -176,7 +176,7 @@ async def _get_results( except asyncio.CancelledError as ex: self.logger.warning(f'process error: {ex!r}') raise - except: + except Exception: # Not sure why, adding this line helps in fixing a hanging test raise diff --git a/jina/clients/base/http.py b/jina/clients/base/http.py index b4469986cdc0f..3bc067a935ac2 100644 --- a/jina/clients/base/http.py +++ b/jina/clients/base/http.py @@ -70,7 +70,7 @@ def extract_paths_by_method(spec): self._endpoints = extract_paths_by_method(openapi_response).get( 'post', [] ) - except: + except Exception: pass async def _is_flow_ready(self, **kwargs) -> bool: diff --git a/jina/clients/base/websocket.py b/jina/clients/base/websocket.py index 01d58b52609f6..8901d6822c448 100644 --- a/jina/clients/base/websocket.py +++ b/jina/clients/base/websocket.py @@ -220,7 +220,7 @@ def _request_handler( exception_raised = ex try: receive_task.cancel() - except: + except Exception: raise ex finally: if iolet.close_code == status.WS_1011_INTERNAL_ERROR: diff --git a/jina/helper.py b/jina/helper.py index b5bcd9759b4b8..e2a03886b8765 100644 --- a/jina/helper.py +++ b/jina/helper.py @@ -941,11 +941,11 @@ def get_full_version() -> Optional[Tuple[Dict, Dict]]: try: from hubble import __version__ as __hubble_version__ - except: + except Exception: __hubble_version__ = 'not-available' try: from jcloud import __version__ as __jcloud_version__ - except: + except Exception: __jcloud_version__ = 'not-available' from jina import __docarray_version__, __proto_version__, __version__ @@ -1220,7 +1220,7 @@ def _get_ip(url): _ip = fp.read().decode().strip() return _ip - except: + except Exception: pass # intentionally ignored, public ip is not showed ip_server_list = [ @@ -1357,7 +1357,7 @@ def download_mermaid_url(mermaid_url, output) -> None: req = Request(mermaid_url, headers={'User-Agent': 'Mozilla/5.0'}) with open(output, 'wb') as fp: fp.write(urlopen(req).read()) - except: + except Exception: from jina.logging.predefined import default_logger default_logger.error( @@ -1658,7 +1658,7 @@ def _telemetry(): ) urllib.request.urlopen(req) - except: + except Exception: pass threading.Thread(target=_telemetry, daemon=True).start() diff --git a/jina/importer.py b/jina/importer.py index e13d93f355ae5..81004ca26620c 100644 --- a/jina/importer.py +++ b/jina/importer.py @@ -169,7 +169,7 @@ def add_modules(*paths): importlib.import_module(path) except ModuleNotFoundError: not_python_module_paths.append(path) - except: + except Exception: raise else: not_python_module_paths.append(path) diff --git a/jina/jaml/helper.py b/jina/jaml/helper.py index f347672f703af..777ac7aa7b7af 100644 --- a/jina/jaml/helper.py +++ b/jina/jaml/helper.py @@ -30,7 +30,7 @@ def get_hashable_key(self, key): """ try: hash(key) - except: + except Exception: if isinstance(key, list): for i in range(len(key)): if not isinstance(key[i], collections.abc.Hashable): diff --git a/jina/orchestrate/deployments/__init__.py b/jina/orchestrate/deployments/__init__.py index e4b6c3a5bc122..a2adec9160f29 100644 --- a/jina/orchestrate/deployments/__init__.py +++ b/jina/orchestrate/deployments/__init__.py @@ -1082,7 +1082,7 @@ def _wait_until_all_ready(self): try: _ = asyncio.get_event_loop() - except: + except Exception: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) @@ -1092,7 +1092,7 @@ async def _f(): running_in_event_loop = False try: asyncio.get_event_loop().run_until_complete(_f()) - except: + except Exception: running_in_event_loop = True if not running_in_event_loop: @@ -1193,7 +1193,7 @@ def wait_start_success(self) -> None: self.gateway_pod.wait_start_success() for shard_id in self.shards: self.shards[shard_id].wait_start_success() - except: + except Exception: self.close() raise @@ -1217,7 +1217,7 @@ async def async_wait_start_success(self) -> None: await asyncio.gather(*coros) self.logger.debug('Deployment started successfully') - except: + except Exception: self.close() raise @@ -1288,7 +1288,7 @@ def _parse_devices(value: str, num_devices: int): if len(parts) == 1: try: int(parts[0]) - except: + except Exception: use_uuids = True if use_uuids: return parts @@ -1297,7 +1297,7 @@ def _parse_devices(value: str, num_devices: int): # try to detect if parts are not numbers try: int(parts[0]) - except: + except Exception: use_uuids = True if not use_uuids: @@ -1328,7 +1328,7 @@ def _roundrobin_cuda_device(device_str: Optional[str], replicas: int): num_devices = str(subprocess.check_output(['nvidia-smi', '-L'])).count( 'UUID' ) - except: + except Exception: num_devices = int(os.environ.get('CUDA_TOTAL_DEVICES', 0)) if num_devices == 0: return diff --git a/jina/orchestrate/deployments/config/helper.py b/jina/orchestrate/deployments/config/helper.py index 472c8c9ab9eb8..fbf8010e83004 100644 --- a/jina/orchestrate/deployments/config/helper.py +++ b/jina/orchestrate/deployments/config/helper.py @@ -93,7 +93,7 @@ def get_base_executor_version(): return __version__ else: return 'master' - except: + except Exception: return 'master' diff --git a/jina/orchestrate/flow/base.py b/jina/orchestrate/flow/base.py index 550aa26a71504..33e2832954f86 100644 --- a/jina/orchestrate/flow/base.py +++ b/jina/orchestrate/flow/base.py @@ -1985,7 +1985,7 @@ async def _async_wait_all(): # kick off all deployments wait-ready tasks try: _ = asyncio.get_event_loop() - except: + except Exception: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) @@ -1995,7 +1995,7 @@ async def _f(): running_in_event_loop = False try: asyncio.get_event_loop().run_until_complete(_f()) - except: + except Exception: running_in_event_loop = True wait_ready_threads = [] @@ -2223,7 +2223,7 @@ def plot( display(Image(url=url)) showed = True - except: + except Exception: # no need to panic users pass diff --git a/jina/orchestrate/pods/container.py b/jina/orchestrate/pods/container.py index c1808542d3aff..b5272c0beee4c 100644 --- a/jina/orchestrate/pods/container.py +++ b/jina/orchestrate/pods/container.py @@ -344,7 +344,7 @@ def _get_control_address(self): ctrl_host = client.networks.get(network).attrs['IPAM']['Config'][0][ 'Gateway' ] - except: + except Exception: ctrl_host = __docker_host__ else: ctrl_host = self.args.host diff --git a/jina/serve/consensus/add_voter/call_add_voter.py b/jina/serve/consensus/add_voter/call_add_voter.py index 06ab97d388509..962efbe810072 100644 --- a/jina/serve/consensus/add_voter/call_add_voter.py +++ b/jina/serve/consensus/add_voter/call_add_voter.py @@ -21,7 +21,7 @@ def call_add_voter(target, replica_id, voter_address): return True else: return False - except: + except Exception: return False @@ -43,5 +43,5 @@ async def async_call_add_voter(target, replica_id, voter_address): return True else: return False - except: + except Exception: return False diff --git a/jina/serve/executors/__init__.py b/jina/serve/executors/__init__.py index 097af0371f57e..0a1b0280866ab 100644 --- a/jina/serve/executors/__init__.py +++ b/jina/serve/executors/__init__.py @@ -115,7 +115,7 @@ def get_inner_pydantic_model(annotation: Type) -> bool: for arg in args: if is_pydantic_model(arg): return arg - except: + except Exception: pass return None @@ -1422,7 +1422,7 @@ def _run_snapshot(self, snapshot_file: str, did_raise_exception): p.touch() with self._write_lock: self.snapshot(snapshot_file) - except: + except Exception: did_raise_exception.set() raise @@ -1430,7 +1430,7 @@ def _run_restore(self, snapshot_file: str, did_raise_exception): try: with self._write_lock: self.restore(snapshot_file) - except: + except Exception: did_raise_exception.set() raise finally: diff --git a/jina/serve/executors/run.py b/jina/serve/executors/run.py index 64bf2ef693c81..a31a49b4579b9 100644 --- a/jina/serve/executors/run.py +++ b/jina/serve/executors/run.py @@ -244,6 +244,6 @@ def signal_handler(*args, **kwargs): worker.join() raft_worker.join() - except: + except Exception: worker.terminate() raft_worker.terminate() diff --git a/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py b/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py index 05af80bd21ec6..311fa7e0c777a 100644 --- a/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py +++ b/jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py @@ -283,7 +283,7 @@ async def event_generator(): try: _ = parameters_model() parameters_model_needed = False - except: + except Exception: parameters_model_needed = True parameters_model = parameters_model if parameters_model_needed else Optional[parameters_model] default_parameters = ( diff --git a/jina/serve/runtimes/head/request_handling.py b/jina/serve/runtimes/head/request_handling.py index e883b901a55ae..009bf035c8b07 100644 --- a/jina/serve/runtimes/head/request_handling.py +++ b/jina/serve/runtimes/head/request_handling.py @@ -243,7 +243,7 @@ async def _handle_data_request( if self._pydantic_models_by_endpoint is None and docarray_v2: try: await self.endpoints_discovery_task - except: + except Exception: raise WorkerRequestHandler.merge_routes(requests) diff --git a/jina/serve/runtimes/servers/__init__.py b/jina/serve/runtimes/servers/__init__.py index fac284970f765..a9b7fc63352a4 100644 --- a/jina/serve/runtimes/servers/__init__.py +++ b/jina/serve/runtimes/servers/__init__.py @@ -37,7 +37,7 @@ def __init__( self.works_as_load_balancer = False try: self.is_cancel = is_cancel or asyncio.Event() - except: + except Exception: # in some unit tests we instantiate the server without an asyncio Loop import threading diff --git a/jina/serve/runtimes/worker/http_csp_app.py b/jina/serve/runtimes/worker/http_csp_app.py index 4fb28a6559c84..2f8786c5aaf42 100644 --- a/jina/serve/runtimes/worker/http_csp_app.py +++ b/jina/serve/runtimes/worker/http_csp_app.py @@ -330,7 +330,7 @@ def construct_model_from_line(model: Type[BaseModel], line: List[str]) -> BaseMo try: _ = parameters_model() parameters_model_needed = False - except: + except Exception: parameters_model_needed = True parameters_model = parameters_model if parameters_model_needed else Optional[parameters_model] default_parameters = ( diff --git a/jina/serve/runtimes/worker/http_fastapi_app.py b/jina/serve/runtimes/worker/http_fastapi_app.py index 42f38a0cb7016..e1ae70baa1624 100644 --- a/jina/serve/runtimes/worker/http_fastapi_app.py +++ b/jina/serve/runtimes/worker/http_fastapi_app.py @@ -172,7 +172,7 @@ async def streaming_get(request: Request = None, body: input_doc_model = None): try: _ = parameters_model() parameters_model_needed = False - except: + except Exception: parameters_model_needed = True parameters_model = parameters_model if parameters_model_needed else Optional[parameters_model] default_parameters = ( diff --git a/jina/serve/stream/__init__.py b/jina/serve/stream/__init__.py index 995c47818e491..3bfb3897ee64a 100644 --- a/jina/serve/stream/__init__.py +++ b/jina/serve/stream/__init__.py @@ -186,7 +186,7 @@ async def stream( if metadatum.key == '__prefetch__': try: prefetch = int(metadatum.value) - except: + except Exception: self.logger.debug(f'Couldn\'t parse prefetch to int value!') try: diff --git a/setup.py b/setup.py index 93cd427075440..b5c2edf91ac03 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ easy_install.main(['fastentrypoints']) pkg_resources.require('fastentrypoints') import fastentrypoint - except: + except Exception: pass try: diff --git a/tests/k8s/test_k8s_deployment.py b/tests/k8s/test_k8s_deployment.py index 1ab58d0accccc..8dd8b61fc03f6 100644 --- a/tests/k8s/test_k8s_deployment.py +++ b/tests/k8s/test_k8s_deployment.py @@ -33,7 +33,7 @@ async def create_executor_deployment_and_wait_ready( try: logger.info(f'create Namespace {namespace}') utils.create_from_dict(api_client, namespace_object) - except: + except Exception: pass while True: diff --git a/tests/k8s/test_k8s_flow.py b/tests/k8s/test_k8s_flow.py index 278b7fde4d316..b13e09b26a224 100644 --- a/tests/k8s/test_k8s_flow.py +++ b/tests/k8s/test_k8s_flow.py @@ -43,7 +43,7 @@ async def create_all_flow_deployments_and_wait_ready( try: logger.info(f'create Namespace {namespace}') utils.create_from_dict(api_client, namespace_object) - except: + except Exception: pass while True: @@ -1056,7 +1056,7 @@ async def _create_external_deployment(api_client, app_client, docker_images, tmp } try: utils.create_from_dict(api_client, namespace_object) - except: + except Exception: pass for filename in filenames: @@ -1066,7 +1066,7 @@ async def _create_external_deployment(api_client, app_client, docker_images, tmp yaml_file=filename, namespace=namespace, ) - except: + except Exception: pass await asyncio.sleep(1.0) @@ -1117,7 +1117,7 @@ async def test_flow_with_failing_executor(logger, docker_images, tmpdir): core_client=core_client, endpoint='/', ) - except: + except Exception: pass await asyncio.sleep(0.5) diff --git a/tests/k8s/test_k8s_graceful_request_handling.py b/tests/k8s/test_k8s_graceful_request_handling.py index efee831f565e1..876936bd8a0dd 100644 --- a/tests/k8s/test_k8s_graceful_request_handling.py +++ b/tests/k8s/test_k8s_graceful_request_handling.py @@ -25,7 +25,7 @@ async def create_all_flow_deployments_and_wait_ready( } try: utils.create_from_dict(api_client, namespace_object) - except: + except Exception: pass deployment_set = set(os.listdir(flow_dump_path)) assert deployment_set == {'gateway', 'slow_process_executor'} diff --git a/tests/k8s_otel/kind_wrapper.py b/tests/k8s_otel/kind_wrapper.py index e861daf44f665..123e45d806377 100644 --- a/tests/k8s_otel/kind_wrapper.py +++ b/tests/k8s_otel/kind_wrapper.py @@ -230,7 +230,7 @@ def port_forward( s = socket.socket() try: s.connect(("127.0.0.1", host_port)) - except: + except Exception: if i >= retries - 1: raise finally: diff --git a/tests/unit/serve/instrumentation/conftest.py b/tests/unit/serve/instrumentation/conftest.py index ad66789e2aeed..19a5443bf5bd2 100644 --- a/tests/unit/serve/instrumentation/conftest.py +++ b/tests/unit/serve/instrumentation/conftest.py @@ -97,7 +97,7 @@ def read_metric_file(filename): print(f'READ {r[0:3]}') try: return json.loads(r) - except: + except Exception: return None ret = {} diff --git a/tests/unit/serve/runtimes/worker/test_worker_runtime.py b/tests/unit/serve/runtimes/worker/test_worker_runtime.py index 8130a554a7495..f6f4c72d1fa3d 100644 --- a/tests/unit/serve/runtimes/worker/test_worker_runtime.py +++ b/tests/unit/serve/runtimes/worker/test_worker_runtime.py @@ -235,7 +235,7 @@ async def test_worker_runtime_slow_init_exec(): try: s.connect((args.host, args.port[0])) connected = True - except: + except Exception: time.sleep(0.2) # Executor sleeps 5 seconds, so at least 5 seconds need to have elapsed here