Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiprocesing socket
#1
Hi iam trying to sent numpy array to multiprocesing socket and always getting error
Does somebody know where is problem ?
This is my server
from multiprocessing.connection import Listener

address = ('localhost', 6000) 
listener = Listener(address, authkey= 'secret password'.encode('utf-8'))
conn = listener.accept()

while True:
    msg = conn.recv()
    print(msg)
And this is my client that sent numpy array to server

from multiprocessing.connection import Client
import numpy as np

a = np.zeros(5)
address = ('localhost', 6000)
conn = Client(address, authkey= 'secret password'.encode('utf-8'))
conn.send(a)

conn.close()
And iam getting this output-

server actually prints out that numpy array but anyway it throws error.
Error:
Traceback (most recent call last): File "C:/Users/samue/PycharmProjects/CONDA/test1.py", line 14, in <module> msg = conn.recv() File "C:\Users\samue\anaconda3\lib\multiprocessing\connection.py", line 250, in recv buf = self._recv_bytes() File "C:\Users\samue\anaconda3\lib\multiprocessing\connection.py", line 414, in _recv_bytes buf = self._recv(4) File "C:\Users\samue\anaconda3\lib\multiprocessing\connection.py", line 383, in _recv raise EOFError [0. 0. 0. 0. 0.] EOFError
Reply
#2
Quote:recv()

Return an object sent from the other end of the connection using send(). Blocks until there is something to receive. Raises EOFError if there is nothing left to receive and the other end was closed.

So the EOFError is expected when the data is done. If you don't want this to exit your program, you need to put it in a try/except and handle the case where the exception is thrown.

while True:
    try:
        msg = conn.recv()
        print(msg)
    except EOFError:
        print("Connection closed.")
        break()
samuelbachorik likes this post
Reply
#3
(Sep-02-2021, 05:46 PM)bowlofred Wrote:
Quote:recv()

Return an object sent from the other end of the connection using send(). Blocks until there is something to receive. Raises EOFError if there is nothing left to receive and the other end was closed.

So the EOFError is expected when the data is done. If you don't want this to exit your program, you need to put it in a try/except and handle the case where the exception is thrown.

while True:
    try:
        msg = conn.recv()
        print(msg)
    except EOFError:
        print("Connection closed.")
        break()

Thank you a lot now i uderstand !
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020