14
14
import os
15
15
import sys
16
16
import tempfile
17
+ import threading
17
18
import zlib
18
19
19
20
from lib .core .compat import xrange
@@ -74,6 +75,7 @@ def __init__(self, items=None):
74
75
self .chunk_length = sys .maxsize
75
76
self .cache = None
76
77
self .filenames = set ()
78
+ self ._lock = threading .Lock ()
77
79
self ._os_remove = os .remove
78
80
self ._size_counter = 0
79
81
@@ -95,18 +97,19 @@ def __iadd__(self, value):
95
97
return self
96
98
97
99
def append (self , value ):
98
- self .chunks [- 1 ].append (value )
99
-
100
- if self .chunk_length == sys .maxsize :
101
- self ._size_counter += _size_of (value )
102
- if self ._size_counter >= BIGARRAY_CHUNK_SIZE :
103
- self .chunk_length = len (self .chunks [- 1 ])
104
- self ._size_counter = None
105
-
106
- if len (self .chunks [- 1 ]) >= self .chunk_length :
107
- filename = self ._dump (self .chunks [- 1 ])
108
- self .chunks [- 1 ] = filename
109
- self .chunks .append ([])
100
+ with self ._lock :
101
+ self .chunks [- 1 ].append (value )
102
+
103
+ if self .chunk_length == sys .maxsize :
104
+ self ._size_counter += _size_of (value )
105
+ if self ._size_counter >= BIGARRAY_CHUNK_SIZE :
106
+ self .chunk_length = len (self .chunks [- 1 ])
107
+ self ._size_counter = None
108
+
109
+ if len (self .chunks [- 1 ]) >= self .chunk_length :
110
+ filename = self ._dump (self .chunks [- 1 ])
111
+ self .chunks [- 1 ] = filename
112
+ self .chunks .append ([])
110
113
111
114
def extend (self , value ):
112
115
for _ in value :
0 commit comments