Skip to content

Commit 083ab54

Browse files
authored
Merge pull request #34 from scrapinghub/test
Avoid races for hubstorage frontier tests
2 parents 1b8cd41 + a77a57c commit 083ab54

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

scrapinghub/hubstorage/batchuploader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def __init__(self, client):
5050
def create_writer(self, url, start=0, auth=None, size=1000, interval=15,
5151
qsize=None, content_encoding='identity',
5252
maxitemsize=1024 ** 2, callback=None):
53+
# callback shouldn't try to inject more items in the queue
54+
# otherwise it can lead to deadlock on _checkpoint step
5355
assert not self.closed, 'Can not create new writers when closed'
5456
auth = xauth(auth) or self.client.auth
5557
w = _BatchWriter(url=url,
@@ -127,13 +129,13 @@ def _checkpoint(self, w):
127129
'content-encoding': w.content_encoding,
128130
})
129131
w.offset += qiter.count
130-
for _ in range(qiter.count):
131-
q.task_done()
132132
if w.callback is not None:
133133
try:
134134
w.callback(response)
135135
except Exception:
136136
logger.exception("Callback for %s failed", w.url)
137+
for _ in range(qiter.count):
138+
q.task_done()
137139

138140
def _content_encode(self, qiter, w):
139141
ce = w.content_encoding

0 commit comments

Comments
 (0)