Ashley Wright
commited on
Commit
·
584b6a4
1
Parent(s):
7ac68ef
Use multiprocessing.connection
Browse files- src/main.py +6 -27
src/main.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from io import BytesIO
|
2 |
-
from
|
3 |
-
from sys import byteorder
|
4 |
from os import chmod
|
5 |
|
6 |
from PIL.JpegImagePlugin import JpegImageFile
|
@@ -17,34 +16,15 @@ def main():
|
|
17 |
|
18 |
print(f"Pipeline loaded")
|
19 |
|
20 |
-
with
|
21 |
-
inference_socket.bind(SOCKET)
|
22 |
-
|
23 |
chmod(SOCKET, 0o777)
|
24 |
|
25 |
-
inference_socket.listen(1)
|
26 |
-
|
27 |
print(f"Awaiting connections")
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
print(f"Connected")
|
32 |
-
|
33 |
-
with connection:
|
34 |
-
connection.setblocking(True)
|
35 |
|
36 |
while True:
|
37 |
-
|
38 |
-
|
39 |
-
print(f"Awaiting message of size {size}")
|
40 |
-
|
41 |
-
message = connection.recv(size).decode("utf-8")
|
42 |
-
|
43 |
-
if not message:
|
44 |
-
print(f"Empty message received")
|
45 |
-
continue
|
46 |
-
|
47 |
-
request = TextToImageRequest.model_validate_json(message)
|
48 |
|
49 |
image = infer(request, pipeline)
|
50 |
|
@@ -53,8 +33,7 @@ def main():
|
|
53 |
|
54 |
packet = data.getvalue()
|
55 |
|
56 |
-
connection.
|
57 |
-
connection.send(packet)
|
58 |
|
59 |
|
60 |
if __name__ == '__main__':
|
|
|
1 |
from io import BytesIO
|
2 |
+
from multiprocessing.connection import Listener
|
|
|
3 |
from os import chmod
|
4 |
|
5 |
from PIL.JpegImagePlugin import JpegImageFile
|
|
|
16 |
|
17 |
print(f"Pipeline loaded")
|
18 |
|
19 |
+
with Listener(SOCKET) as listener:
|
|
|
|
|
20 |
chmod(SOCKET, 0o777)
|
21 |
|
|
|
|
|
22 |
print(f"Awaiting connections")
|
23 |
+
with listener.accept() as connection:
|
24 |
+
print(f"Connected")
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
while True:
|
27 |
+
request = TextToImageRequest.model_validate_json(connection.recv_bytes().decode("utf-8"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
image = infer(request, pipeline)
|
30 |
|
|
|
33 |
|
34 |
packet = data.getvalue()
|
35 |
|
36 |
+
connection.send_bytes(packet)
|
|
|
37 |
|
38 |
|
39 |
if __name__ == '__main__':
|