Error with client initialization

Hi everyone,
Sometimes I get an UnicodeDecodeError or gzip.BadGzipFile error when I initialize a client object. I use multiprocessing package to create some child processes. In each process, a client is initialized. It is strange that these errors do not occur every time.

The UnicodeDecodeError can be caught by an except clause, but gzip.BadGzipFile cannot be caught.

import multiprocessing as mp
from obspy.clients.fdsn import Client
from obspy.clients.fdsn.header import FDSNNoServiceException
import time
import gzip

def test_fun():
    while True:
        try:
            client = Client("IRIS", timeout=600)
        except FDSNNoServiceException:
            print("FDSNNoServiceException. Waiting for 30s before next try ...")
            time.sleep(30)
            continue
        except UnicodeDecodeError:
            print(f"{mp.current_process().name}: UnicodeDecodeError")
            pass
        except gzip.BadGzipFile:
            print(f"{mp.current_process().name}: BadGzipFile")
            pass
        except Exception as e:
            print(f"{mp.current_process().name}: {e}")
            pass
        else:
            print(f"{mp.current_process().name}: Client is initialized successfully")
            break

def run_parallel(num_processes):
    processes = []
    for _ in range(num_processes):
        proc = mp.Process(target=test_fun)
        processes.append(proc)
    for proc in processes:
        proc.start()  # start processes
        #  print(f"{proc.name} started")

    # wait for all processes to complete
    for proc in processes:
        print(f"Is {proc.name} alive? {proc.is_alive()}")
        proc.join()
        print(f"Finished joining {proc.name}")

if __name__ == "__main__":
    run_parallel(20)

Any suggestion is appreciated!

see FDSN client in multiprocessing: UnicodeDecodeError or BadGzipFile error is raised when initializing a client · Issue #3130 · obspy/obspy · GitHub
Please don’t crosspost on the forum and github issue tracker :slight_smile:

1 Like