'Program consumes all the RAM on both server and client
I have a separate file that only takes the camera and puts it on the screen and nothing happens, but when I add the part of sending it through the socket to the server, it begins to consume RAM until it reaches 100% (I have a PC with 32G RAM, so low capacity is not a problem).
SERVER
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
HOST = "x"
PORT = 9090
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((HOST, PORT))
server.listen()
clients_list = []
def broadcast_all(package):
pass
def handle(client):
while True:
try:
package = client.recv(1024)
broadcast_all(package)
except:
index = clients_list.index(client)
clients_list.remove(client)
client.close()
break
def receive():
while True:
client, address = server.accept()
print(f"Conectado desde {str(address)}")
clients_list.append(client)
handle_thread = threading.Thread(target=handle, args=(client))
handle_thread.start()
print("Server Run")
receive()
CLIENT
HOST = 'X'
PORT = 9090
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
def visualizar():
global cap
if cap is not None:
ret, frame = cap.read()
if ret == True:
frame = imutils.resize(frame, width=640)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
im = Image.fromarray(frame)
img = ImageTk.PhotoImage(image=im)
label_video.configure(image=img)
label_video.image = img
sock.send(pickle.dumps(im))
label_video.after(100,visualizar)
else:
label_video.image = ''
cap.release()
def iniciar():
global cap
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
t1 = threading.Thread(target=visualizar)
t1.start()
def terminar():
global cap
cap.release()
Is there any way that I don't consume all the RAM?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
