zeromq - zmq.error.ZMQError: Socket operation on non-socket: How to find alive sockets before closing? -
in application, i'm creating 2 sockets , have try/except this:
try: socketa.connect("tcp://localhost:5557") socketb.bind("tcp://localhost:5558") except zmq.zmqerror e: if e.errno == zmq.einval: logger.error("endpoint supplied invalid") else: logger.error("the zeromq error error number {0}".format(e.errno)) raise zmqerror(e) cleanup()
if reason, 1 of sockets cannot .connect()
/.bind()
, want close both sockets , terminate context in cleanup()
function, how know sockets alive before closing them?
does zeromq provide information active sockets before closing them nicely?
given logic above, let use approach:
case a: both sockets did .connect()
+ .bind()
respectively
case b: of sockets did fail in doing so.
try: socketa.connect( "tcp://localhost:5557" ) socketa.setsockopt( zmq.linger, 0 ) try: socketb.bind( "tcp://localhost:5558" ) socketb.setsockopt( zmq.linger, 0 ) except zmq.zmqerror e: if ( e.errno in ( zmq.einval, zmq.eprotonosupport, zmq.enocompatproto, zmq.eaddrinuse, zmq.eaddrnotavail, ) ): logger.error( "zeromq transportclass / endpoint cannot setup [socketb]." ) if ( e.errno in ( zmq.enodev, zmq.enotsock, ) ): logger.error( "zeromq request made against non-existent device or not using valid socket [socketb]." ) if ( e.errno in ( zmq.eterm, zmq.emthread, ) ): logger.error( "zeromq context not in state handle request [socketb]." ) cleanup( acontextinstance, [ socketa, socketb, ] ) except zmq.zmqerror e: if ( e.errno in ( zmq.einval, zmq.eprotonosupport, zmq.enocompatproto, ) ): logger.error( "zeromq transportclass / endpoint cannot setup [socketa]." ) if ( e.errno in ( zmq.eterm, zmq.emthread, ) ): logger.error( "zeromq context not ready handle request [socketa]." ) if ( e.errno in ( zmq.enotsock, ) ): logger.error( "zeromq operation requested, not on valid [socketa]." ) cleanup( acontextinstance, [ socketa, ] ) finally: # ... pass def cleanup( acontexttoterminate, alistofsocketstoclose = [] ): asocket in alistofsocketstoclose: try: asocket.close() # external responsibility setup linger 0 right @ asocket instantiation point except: pass try: acontexttoterminate.term() except: pass finally: # ... pass
Comments
Post a Comment