M
M
Maxim Kalina2015-04-29 14:46:19
Python
Maxim Kalina, 2015-04-29 14:46:19

How can I restart the script in case of a connection error with the server?

Hello, I have a script like this:

ws = create_connection("ws://153.12.13.51/ws/")
    ws.send("action=auth&login=Terminal13&passw=TTT")
    print ws.recv()
    ws.send("action=code_in&code=0)
    print ws.recv()
    ws.send("action=game&id=3000&verbose=1")
    print ws.recv()
    ws.send("some text")
    print ws.recv()

how to make it so that if it was not possible to connect to the server (some error crawled out), the script tried to reach it until it successfully connected.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Dugin, 2015-04-29
@dayzz

How to make script restart automatically on timeout errors in python?

V
Vladimir Martyanov, 2015-04-29
@vilgeforce

Wrap it in a loop, exiting from which will be carried out only with a successful connection. Install exception hooks that will start the loop from the beginning.

A
Andrey Grinevich, 2015-04-30
@Derfirm

who knows, I use such things on a server, no one has complained yet :)

while True:
    in_msg = self._socket.receive()
    if in_msg is None:
        break
    continue

V
Vov Vov, 2015-07-02
@balamut108

I don’t know what kind of library you have, but in normal libraries there is either a special exception that can be caught, or a method through which the timeout is regulated and what happens next.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question