-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.py
28 lines (24 loc) · 799 Bytes
/
test1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import zmq
import subprocess
import socket
from contextlib import closing
def find_free_port():
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.bind(("", 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return s.getsockname()[1]
if __name__ == "__main__":
messages = [
"Use example_database;",
"SELECT * FROM cars WHERE NAME LIKE 'C__';",
]
port = find_free_port()
conn = subprocess.Popen(["python3", "exceldb/main.py", "-c", str(port)])
context = zmq.Context()
socket = context.socket(zmq.PAIR)
socket.connect(f"tcp://localhost:{port}")
for i in messages:
socket.send_json({"statement": i})
print(socket.recv_json())
# socket.recv_json()
conn.terminate()