Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ Maintenance
* Drop support for Python 2.
By :user:`James Bourbeau <jrbourbeau>`, :issue:`220`.

* Fix leaked semaphore in ``numcodecs.blosc``.
By :user:`John Kirkham <jakirkham>`, :issue:`234`.


.. _release_0.6.4:

Expand Down
7 changes: 0 additions & 7 deletions numcodecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<https://github.com/alimanfoo/numcodecs/issues>`_.

"""
import multiprocessing
import atexit


Expand All @@ -42,13 +41,7 @@
from numcodecs import blosc
from numcodecs.blosc import Blosc
register_codec(Blosc)
# initialize blosc
try:
ncores = multiprocessing.cpu_count()
except OSError: # pragma: no cover
ncores = 1
blosc.init()
blosc.set_nthreads(min(8, ncores))
atexit.register(blosc.destroy)
except ImportError: # pragma: no cover
pass
Expand Down
21 changes: 15 additions & 6 deletions numcodecs/blosc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,34 @@ AUTOSHUFFLE = -1
AUTOBLOCKS = 0

# synchronization
try:
mutex = multiprocessing.Lock()
except OSError:
mutex = None
except ImportError:
mutex = None
mutex = None

# store ID of process that first loads the module, so we can detect a fork later
_importer_pid = os.getpid()


def init():
"""Initialize the Blosc library environment."""
global mutex
# synchronization
try:
mutex = multiprocessing.Lock()
except OSError:
mutex = None
blosc_init()
# set num threads
try:
ncores = multiprocessing.cpu_count()
except OSError:
ncores = 1
set_nthreads(min(8, ncores))


def destroy():
"""Destroy the Blosc library environment."""
global mutex
blosc_destroy()
mutex = None


def compname_to_compcode(cname):
Expand Down