Skip to content

Commit

Permalink
refactor(fork): working with fork fix from ape core
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Oct 28, 2024
1 parent 5dc3025 commit 6f4b117
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions silverback/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import atexit
import inspect
from collections import defaultdict
Expand Down Expand Up @@ -235,22 +234,19 @@ async def __create_snapshot_handler(
# To ensure we don't have too many forks at once
# HACK: Until `NetworkManager.fork` (and `ProviderContextManager`) allows concurrency

fork_lock: asyncio.Lock = asyncio.Lock()

def _with_fork_decorator(self, handler: Callable) -> Callable:
# Trigger worker-side handling using fork network by wrapping handler
fork_context = self.provider.network_manager.fork

@wraps(handler)
async def fork_handler(*args, **kwargs):
async with self.fork_lock:
with fork_context():
result = handler(*args, **kwargs)
with fork_context():
result = handler(*args, **kwargs)

if inspect.isawaitable(result):
return await result
if inspect.isawaitable(result):
return await result

return result
return result

return fork_handler

Expand Down

0 comments on commit 6f4b117

Please sign in to comment.