I am running a python script that subscribe to a websocket feed, I would like to have the script to be started (a new instance ) when a certain event in the code is triggered, in my case a disconnection from the server.
my python file code :
class Client:
    
    def __init__(self, client_id, qties, on_data):
        self.responses = []
        headers = self.create_headers(self.api_key, self.secret_key, self.passphrase)
        socketio_client = socketio.Client()
        @socketio_client.on('disconnect', namespace='/streaming')
        def on_disconnect():
            print('Server disconnected.')
            quit()
               ^^^^
        @socketio_client.on('connect_error', namespace='/streaming')
        def on_connect_error(msg):
            print(f'Cannot connect to the server. Error: {msg}')
            quit()
        @socketio_client.on('stream',namespace='/streaming')
        def on_price(res):
            on_data(res)
            print(f"Response from Client {client_id} @ {time.time()}")
...
I would like to replace the quit() on on_disconnect() by some code that runs the file from the begining.
 
    