dsmq 1.1.0__py3-none-any.whl → 1.2.1__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/server.py CHANGED
@@ -19,7 +19,7 @@ _db_name = "file::memory:?cache=shared"
19
19
  dsmq_server = None
20
20
 
21
21
 
22
- def serve(host=_default_host, port=_default_port):
22
+ def serve(host=_default_host, port=_default_port, verbose=False):
23
23
  """
24
24
  For best results, start this running in its own process and walk away.
25
25
  """
@@ -50,11 +50,13 @@ CREATE TABLE IF NOT EXISTS messages (timestamp DOUBLE, topic TEXT, message TEXT)
50
50
  # or send it to me at brohrer@gmail.com,
51
51
  global dsmq_server
52
52
 
53
- dsmq_server = ws_serve(request_handler, host, port)
54
- dsmq_server.serve_forever()
55
- print()
56
- print(f"Server started at {host} on port {port}.")
57
- print("Waiting for clients...")
53
+ # dsmq_server = ws_serve(request_handler, host, port)
54
+ with ws_serve(request_handler, host, port) as dsmq_server:
55
+ dsmq_server.serve_forever()
56
+ if verbose:
57
+ print()
58
+ print(f"Server started at {host} on port {port}.")
59
+ print("Waiting for clients...")
58
60
 
59
61
  sqlite_conn.close()
60
62
 
@@ -140,11 +142,9 @@ AND timestamp = a.min_time
140
142
  elif msg["action"] == "shutdown":
141
143
  # Run this from a separate thread to prevent deadlock
142
144
  global dsmq_server
143
- print("Shutting down the dsmq server.")
144
145
 
145
146
  def shutdown_gracefully(server_to_shutdown):
146
147
  server_to_shutdown.shutdown()
147
- time.sleep(_pause)
148
148
 
149
149
  filenames = os.listdir()
150
150
  for filename in filenames:
@@ -155,9 +155,11 @@ AND timestamp = a.min_time
155
155
  pass
156
156
 
157
157
  Thread(target=shutdown_gracefully, args=(dsmq_server,)).start()
158
- sqlite_conn.close()
158
+ break
159
159
  else:
160
- print("Action must either be 'put', 'get', or 'shudown'")
160
+ raise RuntimeWarning(
161
+ "dsmq client action must either be 'put', 'get', or 'shutdown'"
162
+ )
161
163
 
162
164
  # Periodically clean out messages from the queue that are
163
165
  # past their sell buy date.
@@ -1,5 +1,6 @@
1
1
  import multiprocessing as mp
2
2
  import time
3
+ from websockets.exceptions import ConnectionClosed
3
4
  from dsmq.server import serve
4
5
  from dsmq.client import connect
5
6
 
@@ -12,7 +13,7 @@ port = 30303
12
13
  _short_pause = 0.001
13
14
  _pause = 0.01
14
15
  _long_pause = 0.1
15
- _very_long_pause = 0.1
16
+ _very_long_pause = 2.0
16
17
 
17
18
 
18
19
  def test_client_server():
@@ -38,9 +39,13 @@ def test_client_server():
38
39
  mq.shutdown_server()
39
40
  mq.close()
40
41
 
41
- # It takes a sec to shut down the server
42
- time.sleep(_long_pause)
43
- assert not p_server.is_alive()
42
+ closed = False
43
+ try:
44
+ mq = connect(host, port)
45
+ except ConnectionRefusedError as e:
46
+ print(e)
47
+ closed = True
48
+ assert closed
44
49
 
45
50
 
46
51
  def test_write_one_read_one():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dsmq
3
- Version: 1.1.0
3
+ Version: 1.2.1
4
4
  Summary: A dead simple message queue
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.10
@@ -3,10 +3,10 @@ dsmq/client.py,sha256=2i3BhpQM71j-uZlqiJvzQgywi1y07K1VgQe8i2Koi0g,2070
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=iiaa7IoxZy1143vwTO7eMD-kzUKTTVff37E3KPpJ4cU,6010
6
+ dsmq/server.py,sha256=kCqBzgikvJlCgAfLHd18LS7fmkYW6e0RhmdwqdeXJ7Q,6079
7
7
  dsmq/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- dsmq/tests/integration_test.py,sha256=TJyx_wsFWeSvYuMF7vCNSGcWstTSLZbuAeKrxrQcj98,5930
9
- dsmq-1.1.0.dist-info/METADATA,sha256=S72f4YPsNO07F8W4cnrhGGEW-4Eoao9BBh2VP28uziM,4730
10
- dsmq-1.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- dsmq-1.1.0.dist-info/licenses/LICENSE,sha256=3Yu1mAp5VsKmnDtzkiOY7BdmrLeNwwZ3t6iWaLnlL0Y,1071
12
- dsmq-1.1.0.dist-info/RECORD,,
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,,
File without changes