code: def read_packet(sock, timeout=None):
      
      sock.settimeout(timeout)
      dlen, data = None, None
      try:
          if os.name == 'nt':
              #  Windows implementation
              datalen = sock.recv(SZ)
              dlen, = struct.unpack("l", datalen)
              data = b''
              while len(data) < dlen:
                  data += sock.recv(dlen)
          else:
              #  Linux/MacOSX implementation
              #  Thanks to eborisch:
              #  See issue 1106
              datalen = temp_fail_retry(socket.error, sock.recv,
                                        SZ, socket.MSG_WAITALL)
              if len(datalen) == SZ:
                  dlen, = struct.unpack("l", datalen)
                  data = temp_fail_retry(socket.error, sock.recv,
                                         dlen, socket.MSG_WAITALL)
      except socket.timeout:
          raise
      except socket.error:
          data = None
      finally:
          sock.settimeout(None)
      if data is not None:
          try:
              return pickle.loads(data)
          except Exception:
              # Catch all exceptions to avoid locking spyder
              if DEBUG_EDITOR:
                  traceback.print_exc(file=STDERR)
              return
docs: Read data from socket *sock*
      Returns None if something went wrong