dsmq 1.2.1__py3-none-any.whl → 1.2.3__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.
dsmq/client.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import json
2
2
  import time
3
3
  from websockets.sync.client import connect as ws_connect
4
+ from websockets.exceptions import ConnectionClosedError
4
5
 
5
6
  _default_host = "127.0.0.1"
6
7
  _default_port = 30008
@@ -9,14 +10,16 @@ _n_retries = 10
9
10
  _initial_retry = 0.01 # seconds
10
11
 
11
12
 
12
- def connect(host=_default_host, port=_default_port):
13
- return DSMQClientSideConnection(host, port)
13
+ def connect(host=_default_host, port=_default_port, verbose=False):
14
+ return DSMQClientSideConnection(host, port, verbose=verbose)
14
15
 
15
16
 
16
17
  class DSMQClientSideConnection:
17
- def __init__(self, host, port):
18
+ def __init__(self, host, port, verbose=False):
18
19
  self.uri = f"ws://{host}:{port}"
19
- print(f"Connecting to dsmq server at {self.uri}")
20
+ self.verbose = verbose
21
+ if self.verbose:
22
+ print(f"Connecting to dsmq server at {self.uri}")
20
23
  for i_retry in range(_n_retries):
21
24
  try:
22
25
  self.websocket = ws_connect(self.uri)
@@ -26,7 +29,8 @@ class DSMQClientSideConnection:
26
29
  # Exponential backoff
27
30
  # Wait twice as long each time before trying again.
28
31
  time.sleep(_initial_retry * 2**i_retry)
29
- print(" ...trying again")
32
+ if self.verbose:
33
+ print(" ...trying again")
30
34
 
31
35
  if self.websocket is None:
32
36
  raise ConnectionRefusedError("Could not connect to dsmq server.")
@@ -36,7 +40,11 @@ class DSMQClientSideConnection:
36
40
  def get(self, topic):
37
41
  msg = {"action": "get", "topic": topic}
38
42
  self.websocket.send(json.dumps(msg))
39
- msg_text = self.websocket.recv()
43
+ try:
44
+ msg_text = self.websocket.recv()
45
+ except ConnectionClosedError:
46
+ self.close()
47
+
40
48
  msg = json.loads(msg_text)
41
49
  return msg["message"]
42
50
 
dsmq/server.py CHANGED
@@ -5,6 +5,7 @@ import sys
5
5
  from threading import Thread
6
6
  import time
7
7
  from websockets.sync.server import serve as ws_serve
8
+ from websockets.exceptions import ConnectionClosedError
8
9
 
9
10
  _default_host = "127.0.0.1"
10
11
  _default_port = 30008
@@ -138,7 +139,10 @@ AND timestamp = a.min_time
138
139
  # Handle the case where no results are returned
139
140
  message = ""
140
141
 
141
- websocket.send(json.dumps({"message": message}))
142
+ try:
143
+ websocket.send(json.dumps({"message": message}))
144
+ except ConnectionClosedError:
145
+ pass
142
146
  elif msg["action"] == "shutdown":
143
147
  # Run this from a separate thread to prevent deadlock
144
148
  global dsmq_server
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dsmq
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: A dead simple message queue
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.10
@@ -1,12 +1,12 @@
1
1
  dsmq/__init__.py,sha256=YCgbnQAk8YbtHRyMcU0v2O7RdRhPhlT-vS_q40a7Q6g,50
2
- dsmq/client.py,sha256=2i3BhpQM71j-uZlqiJvzQgywi1y07K1VgQe8i2Koi0g,2070
2
+ dsmq/client.py,sha256=p6irQZOE4b2fpTUwSrEUraPmrJzvT8QSU01ak9qpGCQ,2351
3
3
  dsmq/demo.py,sha256=K53cC5kN7K4kNJlPq7c5OTIMHRCKTo9hYX2aIos57rU,542
4
4
  dsmq/example_get_client.py,sha256=PvAsDGEAH1kVBifLVg2rx8ZxnAZmvzVCvZq13VgpLds,301
5
5
  dsmq/example_put_client.py,sha256=QxDc3i7KAjjhpwxRRpI0Ke5KTNSPuBf9kkcGyTvUEaw,353
6
- dsmq/server.py,sha256=kCqBzgikvJlCgAfLHd18LS7fmkYW6e0RhmdwqdeXJ7Q,6079
6
+ dsmq/server.py,sha256=HkV1yTYe0u_P6TZVAS_wBkT6TDLySfmdZPVvt-VyeF0,6219
7
7
  dsmq/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  dsmq/tests/integration_test.py,sha256=lC97LAzdQixv75OwjqjKTvYnSZpsP0zuzFP8ocUnjl8,6031
9
- dsmq-1.2.1.dist-info/METADATA,sha256=6DSNtpbtnGbwQ5nGM0_tX1lQaxP7VWFmcBH8mU-RAN0,4730
10
- dsmq-1.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- dsmq-1.2.1.dist-info/licenses/LICENSE,sha256=3Yu1mAp5VsKmnDtzkiOY7BdmrLeNwwZ3t6iWaLnlL0Y,1071
12
- dsmq-1.2.1.dist-info/RECORD,,
9
+ dsmq-1.2.3.dist-info/METADATA,sha256=H3t1g1Hs68VsheHaCqzrp2bs1ekwzUM5ajC7bzgjH34,4730
10
+ dsmq-1.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
+ dsmq-1.2.3.dist-info/licenses/LICENSE,sha256=3Yu1mAp5VsKmnDtzkiOY7BdmrLeNwwZ3t6iWaLnlL0Y,1071
12
+ dsmq-1.2.3.dist-info/RECORD,,
File without changes