1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Python socket で connection が張れるまで待つメモ

Posted at

RPC なり TCP/IP のスクリプトで, 相手方がプロセス再起動するなどして一時的に通信ができないときにいくらか待ちたい.

何もしないと connection refused エラーが Python スクリプトが落ちてしまう.

ありがとうございます.

while True:
    try:
        yarr.call(('localhost', 8000), 'proc_numpy', a)

        break
    except socket_error as serr:
        if serr.errno != errno.ECONNREFUSED:
            # Not the error we are looking for, re-raise
            raise serr

        print("sleep")
        time.sleep(0.1)

のような感じでいけました!

timeout 機能をつける

timeout-decoratorを利用して自作関数にタイムアウトを設定する
https://qiita.com/komorin0521/items/0ca7eacb7ae9424fc6c4

ありがとうございます.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?