locust-cloud 1.12.3__py3-none-any.whl → 1.12.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
locust_cloud/cloud.py CHANGED
@@ -3,7 +3,7 @@ import gzip
3
3
  import logging
4
4
  import os
5
5
  import sys
6
- import time
6
+ import threading
7
7
  import tomllib
8
8
  import urllib.parse
9
9
  from argparse import Namespace
@@ -314,22 +314,19 @@ def main() -> None:
314
314
  logger.debug("Load generators deployed successfully!")
315
315
  logger.info("Waiting for pods to be ready...")
316
316
 
317
+ shutdown_allowed = threading.Event()
318
+ shutdown_allowed.set()
319
+ reconnect_aborted = threading.Event()
320
+ connect_timeout = threading.Timer(2 * 60, reconnect_aborted.set)
321
+
317
322
  try:
318
323
  ws_connection_info = urllib.parse.urlparse(log_ws_url)
319
324
  sio = socketio.Client(handle_sigint=False)
320
325
 
321
- run = True
322
-
323
- def wait():
324
- logger.debug("Waiting for shutdown event")
325
- while run:
326
- time.sleep(0.1)
327
-
328
- logger.debug("Shutting down websocket connection")
329
- sio.shutdown()
330
-
331
326
  @sio.event
332
327
  def connect():
328
+ shutdown_allowed.clear()
329
+ connect_timeout.cancel()
333
330
  logger.debug("Websocket connection established, switching to Locust logs")
334
331
 
335
332
  @sio.event
@@ -350,33 +347,33 @@ def main() -> None:
350
347
  if message:
351
348
  print(message)
352
349
 
353
- nonlocal run
354
- run = False
355
-
356
- for _ in range(5 * 60): # try for 5 minutes
357
- try:
358
- sio.connect(
359
- f"{ws_connection_info.scheme}://{ws_connection_info.netloc}", socketio_path=ws_connection_info.path
360
- )
361
- break
362
- except socketio.exceptions.ConnectionError:
363
- time.sleep(1)
364
-
365
- else: # no break
366
- raise Exception("Failed to obtain socket connection")
367
-
368
- wait()
350
+ shutdown_allowed.set()
351
+
352
+ # The _reconnect_abort value on the socketio client will be populated with a newly created threading.Event if it's not already set.
353
+ # There is no way to set this by passing it in the constructor.
354
+ # This event is the only way to interupt the retry logic when the connection is attempted.
355
+ sio._reconnect_abort = reconnect_aborted
356
+ connect_timeout.start()
357
+ sio.connect(
358
+ f"{ws_connection_info.scheme}://{ws_connection_info.netloc}",
359
+ socketio_path=ws_connection_info.path,
360
+ retry=True,
361
+ )
362
+ logger.debug("Waiting for shutdown")
363
+ shutdown_allowed.wait()
369
364
 
370
365
  except KeyboardInterrupt:
371
366
  logger.debug("Interrupted by user")
372
367
  delete(credential_manager)
373
- wait()
368
+ shutdown_allowed.wait(timeout=90)
374
369
  except Exception as e:
375
370
  logger.exception(e)
376
371
  delete(credential_manager)
377
372
  sys.exit(1)
378
373
  else:
379
374
  delete(credential_manager)
375
+ finally:
376
+ sio.shutdown()
380
377
 
381
378
 
382
379
  def delete(credential_manager):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: locust-cloud
3
- Version: 1.12.3
3
+ Version: 1.12.4
4
4
  Summary: Locust Cloud
5
5
  Project-URL: Homepage, https://locust.cloud
6
6
  Requires-Python: >=3.11
@@ -1,6 +1,6 @@
1
1
  locust_cloud/__init__.py,sha256=F_-Mzw8-OpWEwpnhdIL_PWG2aDOYTXkmZSU11G5GH9s,3914
2
2
  locust_cloud/auth.py,sha256=FTQZvMadDfq7nwVlKfAITp2rI960YBpr6KO7QnXi8i0,17616
3
- locust_cloud/cloud.py,sha256=wiVzqcFoOZRnACg4JVrpmXggXxfJcJ9WlUSSj11abMo,13917
3
+ locust_cloud/cloud.py,sha256=xXe7PJGVFi__93nps9wXpJ71Tt6nboYCz_m7s4apsyo,14178
4
4
  locust_cloud/credential_manager.py,sha256=MiESqS8IOxncBON04irK1-seF-VNAHHTcELcyxp1ZR8,5571
5
5
  locust_cloud/idle_exit.py,sha256=bYD6LeUa0d8Ev2b1f-tiRXVnfyolCoACcDWC8zizNPE,1189
6
6
  locust_cloud/socket_logging.py,sha256=ZQ6_a1NrSNxmLI_LWDcmS6p5RVkc8LsEnN177JoRKyg,4461
@@ -19,7 +19,7 @@ locust_cloud/webui/vitest.config.ts,sha256=Rb-lqfCVqW5EAvBCZ-U7LO-tqHbIBc_bQEvfZ
19
19
  locust_cloud/webui/yarn.lock,sha256=slIO1G7Eb2H9bFM4suyh24Mr4YGRM4bHjUhJAmSGdG4,266408
20
20
  locust_cloud/webui/dist/index.html,sha256=o7Wt2gMtE81eDJcqvbPXQ6ssS1qwfcYuMM3OzcaFzhA,664
21
21
  locust_cloud/webui/dist/assets/index-D3YieuNV.js,sha256=EtQvL7--QPGFf3JL_EFSjfdgN2I_uzr6o-hKpTqynXU,2870983
22
- locust_cloud-1.12.3.dist-info/METADATA,sha256=_1GlLHUWrZzjo7J6c0gMfbcBjDrc9wmaTyoIUsHLyMA,545
23
- locust_cloud-1.12.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
24
- locust_cloud-1.12.3.dist-info/entry_points.txt,sha256=PGyAb4e3aTsGS3N3VGShDl6VzJaXy7QwsEgsLOC7V00,57
25
- locust_cloud-1.12.3.dist-info/RECORD,,
22
+ locust_cloud-1.12.4.dist-info/METADATA,sha256=DAfqogr5gZYO6p68ilZsvphzWsGdEfCBz7lqjNvwR3w,545
23
+ locust_cloud-1.12.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
24
+ locust_cloud-1.12.4.dist-info/entry_points.txt,sha256=PGyAb4e3aTsGS3N3VGShDl6VzJaXy7QwsEgsLOC7V00,57
25
+ locust_cloud-1.12.4.dist-info/RECORD,,