Should I close the zeromq kernel explicitly in python?

In languages โ€‹โ€‹like C / C ++, closing the zeromq core explicitly requires what I understand. But in some higher-level languages, such as php and python, which have a garbage collection mechanism, should I explicitly close sockets?

There is no ZMQSocket :: close () in php, and in python, the pyzmq doc says socket.close () can be omitted since it will be automatically closed during garbage collection.

So my question is: do I need to manually close it or not? ...

+5
source share
4 answers

-, . . , . . , , , , . , , , , .

: . , , . - , , .

+2

-

, ( Context.term() , .

pyzmq changelog states, 14.3.0 , Python 3.4 โ€‹โ€‹ .

docstrings Context.term() socket.close() .

+2

. Python, :

  • , , , .
  • , . , -. , .

, Python.

+1

.

. , __del__(). CPython , , . Jython .. -.

- , , , , .

2.5 2.6 , . , goot :

with open(...) as f:
    # do stuff with file object f
# now it is automatically closed.

zeromq, , , .

I am personally sloppy if I work single-line through the command line, but is usually quite strict in complete programs. Better to be explicit than implicit.

+1
source

All Articles