Skip to content

Commit

Permalink
Add lock around add_item_for call which is multi-threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit74 committed Jan 13, 2025
1 parent ad8214d commit 8c58241
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scraper/src/mindtouch2zim/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

context = Context.get()
logger = context.logger
lock = threading.Lock()


class HeaderData(NamedTuple):
Expand Down Expand Up @@ -154,10 +155,11 @@ def process_asset(
kind=asset_details.kind,
)
logger.debug(f"Adding asset to {asset_path.value} in the ZIM")
creator.add_item_for(
path="content/" + asset_path.value,
content=asset_content.getvalue(),
)
with lock:
creator.add_item_for(
path="content/" + asset_path.value,
content=asset_content.getvalue(),
)
break # file found and added
except RuntimeError:
# RuntimeError exceptions comes from the libzim usually and they must be
Expand Down

0 comments on commit 8c58241

Please sign in to comment.