18
18
19
19
20
20
class _NullLock (object ):
21
- """The ``_NullLock`` is an object which can be used in place of a
21
+ """Can be used as no-function dummy object in place of ``threading.lock``.
22
+
23
+ The ``_NullLock`` is an object which can be used in place of a
22
24
``threading.Lock`` object, but doesn't actually do anything.
23
25
24
26
It is used by the ``read_segments`` function in the event that a
@@ -648,12 +650,14 @@ def read_segments(fileobj, segments, n_bytes, lock=None):
648
650
absolute file offset in bytes and number of bytes to read
649
651
n_bytes : int
650
652
total number of bytes that will be read
651
- lock : threading.Lock
653
+ lock : {None, threading.Lock, lock-like} optional
652
654
If provided, used to ensure that paired calls to ``seek`` and ``read``
653
655
cannot be interrupted by another thread accessing the same ``fileobj``.
654
656
Each thread which accesses the same file via ``read_segments`` must
655
657
share a lock in order to ensure that the file access is thread-safe.
656
- A lock does not need to be provided for single-threaded access.
658
+ A lock does not need to be provided for single-threaded access. The
659
+ default value (``None``) results in a lock-like object (a
660
+ ``_NullLock``) which does not do anything.
657
661
658
662
Returns
659
663
-------
@@ -763,9 +767,14 @@ def fileslice(fileobj, sliceobj, shape, dtype, offset=0, order='C',
763
767
returning one of 'full', 'contiguous', None. See
764
768
:func:`optimize_slicer` and see :func:`threshold_heuristic` for an
765
769
example.
766
- lock: threading.Lock, optional
770
+ lock : {None, threading.Lock, lock-like} optional
767
771
If provided, used to ensure that paired calls to ``seek`` and ``read``
768
772
cannot be interrupted by another thread accessing the same ``fileobj``.
773
+ Each thread which accesses the same file via ``read_segments`` must
774
+ share a lock in order to ensure that the file access is thread-safe.
775
+ A lock does not need to be provided for single-threaded access. The
776
+ default value (``None``) results in a lock-like object (a
777
+ ``_NullLock``) which does not do anything.
769
778
770
779
Returns
771
780
-------
@@ -779,8 +788,8 @@ def fileslice(fileobj, sliceobj, shape, dtype, offset=0, order='C',
779
788
segments , sliced_shape , post_slicers = calc_slicedefs (
780
789
sliceobj , shape , itemsize , offset , order )
781
790
n_bytes = reduce (operator .mul , sliced_shape , 1 ) * itemsize
782
- bytes = read_segments (fileobj , segments , n_bytes , lock )
783
- sliced = np .ndarray (sliced_shape , dtype , buffer = bytes , order = order )
791
+ arr_data = read_segments (fileobj , segments , n_bytes , lock )
792
+ sliced = np .ndarray (sliced_shape , dtype , buffer = arr_data , order = order )
784
793
return sliced [post_slicers ]
785
794
786
795
0 commit comments