zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.45k stars 2.34k forks source link

No IPC Support for Windows, probably because of missing AF_UNIX support? #4677

Closed TKaluza closed 1 month ago

TKaluza commented 2 months ago

Please use this template for reporting suspected bugs or requests for help.

Issue description

With pyzmq version 22.2.0 there was IPC supported in Windows, which I really am using a lot. This got probably dropped in 24.0.0

Question

Is there some link or info when this might get fixed within libzmq?

AF_UNIX support will be re-enabled in pyzmq wheels when libzmq published fixed releases. ReleaseNote24.0.0.

TKaluza commented 1 month ago

In Windows 11 with the new 26 pyzmq version ipc seems to work. So this can be closed propably?

import zmq
import os
import numpy as np
import logging
from multiprocessing import Process

# Configure logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

# Create a random numpy array of 1MB
array_size = 1 * 1024 * 1024 // 8  # 1MB of float64
random_array = np.random.rand(array_size)

# Save the array to a file
filename = 'random_array.npy'
np.save(filename, random_array)
logging.debug(f'Saved random array to {filename}')

# Define the IPC endpoint
ipc_endpoint = 'ipc://test_ipc.ipc'

def server():
    logging.debug('Server: Starting...')
    context = zmq.Context()
    socket = context.socket(zmq.REP)
    socket.bind(ipc_endpoint)
    logging.debug(f'Server: Bound to {ipc_endpoint}')

    message = socket.recv()
    logging.debug('Server: Received message')

    # Save the received message to a numpy file
    received_array = np.frombuffer(message, dtype=np.float64)
    np.save('received_array.npy', received_array)
    logging.debug('Server: Saved received array to received_array.npy')

    # Load the original array from file
    original_array = np.load(filename)
    logging.debug('Server: Loaded original array from file')

    # Load the received array from file
    loaded_received_array = np.load('received_array.npy')
    logging.debug('Server: Loaded received array from file')

    # Compare the arrays
    if np.array_equal(loaded_received_array, original_array):
        socket.send_string("SUCCESS")
        logging.info("SUCCESS for IPC")
        logging.debug('Server: Arrays match. Sent SUCCESS to client')
    else:
        socket.send_string("FAILURE")
        logging.debug('Server: Arrays do not match. Sent FAILURE to client')

def client():
    logging.debug('Client: Starting...')
    context = zmq.Context()
    socket = context.socket(zmq.REQ)
    socket.connect(ipc_endpoint)
    logging.debug(f'Client: Connected to {ipc_endpoint}')

    # Load the original array from file
    original_array = np.load(filename)
    logging.debug('Client: Loaded original array from file')

    # Send the array as bytes
    socket.send(original_array.tobytes())
    logging.debug('Client: Sent data to server')

    result = socket.recv_string()
    logging.debug(f'Client: Received result from server: {result}')
    return result

if __name__ == '__main__':
    logging.debug('Main: Starting server and client processes')

    server_process = Process(target=server)
    server_process.start()
    logging.debug('Main: Server process started')

    client_process = Process(target=client)
    client_process.start()
    logging.debug('Main: Client process started')

    client_process.join()
    server_process.join()
    logging.debug('Main: Server and client processes joined')

    # Clean up the generated files
    os.remove(filename)
    os.remove('received_array.npy')
    logging.debug('Main: Cleaned up generated files')