Skip to content

Commit 976e481

Browse files
committed
leave comments about critical section there
1 parent 1138967 commit 976e481

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/apify/_charging.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ def calculate_chargeable() -> dict[str, int | None]:
232232
# Acquire lock to prevent race conditions between concurrent charge calls
233233
# (e.g., when Actor.push_data with charging is called concurrently with Actor.charge).
234234
async with self._charge_lock:
235+
# START OF CRITICAL SECTION
236+
235237
# Determine the maximum amount of events that can be charged within the budget
236238
max_chargeable = self.calculate_max_event_charge_count_within_limit(event_name)
237239
charged_count = min(count, max_chargeable if max_chargeable is not None else count)
@@ -279,6 +281,8 @@ def calculate_chargeable() -> dict[str, int | None]:
279281
}
280282
)
281283

284+
# END OF CRITICAL SECTION
285+
282286
# If it is not possible to charge the full amount, log that fact
283287
if charged_count < count:
284288
subject = 'instance' if count == 1 else 'instances'

0 commit comments

Comments
 (0)