It is considered good style to close ressources you use.
Normally, things are closed during garbage collection. But it is an implementation detail when __del__()
is called. In CPython, you have reference counting and objects are discarded as soon as they are not used any longer. Other implementations as Jython etc. might work differently.
An implementation is allowed to postpone garbage collection or omit it altogether – it is a matter of implementation quality how garbage collection is implemented, as long as no objects are collected that are still reachable.
In 2.5 or 2.6, context managers were introduced in order to cope with exactly that kind of problems. Since then, it is considered goot style to work with files in this way:
with open(...) as f:
# do stuff with file object f
# now it is automatically closed.
I don't know zeromq, but it might be that it has support for context managers as well.
I personally am sloppy if I work one-linerish via command line, but tend to be rather strict in complete programs. It is better to be explicit than implicit.