We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python における素晴らしい WebSocket ライブラリである websockets の再接続実装を参考にして、pybotters の再接続ロジックに同等のバックオフ機能を実装します。
websockets
Client.ws_connect
backoff
websocketes
https://github.com/python-websockets/websockets/blob/12.0/src/websockets/legacy/client.py#L589-L624
BACKOFF_MIN = 1.92 BACKOFF_MAX = 60.0 BACKOFF_FACTOR = 1.618 BACKOFF_INITIAL = 5 async def __aiter__(self) -> AsyncIterator[WebSocketClientProtocol]: backoff_delay = self.BACKOFF_MIN while True: try: async with self as protocol: yield protocol except Exception: # Add a random initial delay between 0 and 5 seconds. # See 7.2.3. Recovering from Abnormal Closure in RFC 6544. if backoff_delay == self.BACKOFF_MIN: initial_delay = random.random() * self.BACKOFF_INITIAL self.logger.info( "! connect failed; reconnecting in %.1f seconds", initial_delay, exc_info=True, ) await asyncio.sleep(initial_delay) else: self.logger.info( "! connect failed again; retrying in %d seconds", int(backoff_delay), exc_info=True, ) await asyncio.sleep(int(backoff_delay)) # Increase delay with truncated exponential backoff. backoff_delay = backoff_delay * self.BACKOFF_FACTOR backoff_delay = min(backoff_delay, self.BACKOFF_MAX) continue else: # Connection succeeded - reset backoff delay backoff_delay = self.BACKOFF_MIN
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Summary
Python における素晴らしい WebSocket ライブラリである
websockets
の再接続実装を参考にして、pybotters の再接続ロジックに同等のバックオフ機能を実装します。Client.ws_connect
の引数backoff
で指定することができますReference from
websocketes
https://github.com/python-websockets/websockets/blob/12.0/src/websockets/legacy/client.py#L589-L624
The text was updated successfully, but these errors were encountered: