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 +12 -10
- dsmq/tests/integration_test.py +9 -4
- {dsmq-1.1.0.dist-info → dsmq-1.2.1.dist-info}/METADATA +1 -1
- {dsmq-1.1.0.dist-info → dsmq-1.2.1.dist-info}/RECORD +6 -6
- {dsmq-1.1.0.dist-info → dsmq-1.2.1.dist-info}/WHEEL +0 -0
- {dsmq-1.1.0.dist-info → dsmq-1.2.1.dist-info}/licenses/LICENSE +0 -0
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
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
158
|
+
break
|
159
159
|
else:
|
160
|
-
|
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.
|
dsmq/tests/integration_test.py
CHANGED
@@ -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
|
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
|
-
|
42
|
-
|
43
|
-
|
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():
|
@@ -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=
|
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=
|
9
|
-
dsmq-1.1.
|
10
|
-
dsmq-1.1.
|
11
|
-
dsmq-1.1.
|
12
|
-
dsmq-1.1.
|
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
|
File without changes
|