Skip to content

Commit

Permalink
Remove file lock and pass through client in Block.load
Browse files Browse the repository at this point in the history
  • Loading branch information
desertaxle committed Jul 29, 2024
1 parent 896d982 commit 0415d96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/prefect/blocks/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,9 @@ class Custom(Block):
loaded_block.save("my-custom-message", overwrite=True)
```
"""
block_document, block_document_name = await cls._get_block_document(name)
block_document, block_document_name = await cls._get_block_document(
name, client=client
)

return cls._load_from_block_document(block_document, validate=validate)

Expand Down
9 changes: 3 additions & 6 deletions src/prefect/server/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from fastapi.openapi.utils import get_openapi
from fastapi.responses import JSONResponse
from fastapi.staticfiles import StaticFiles
from filelock import FileLock
from starlette.exceptions import HTTPException

import prefect
Expand Down Expand Up @@ -747,7 +746,6 @@ def openapi():

class SubprocessASGIServer:
_instances: Dict[Union[int, None], "SubprocessASGIServer"] = {}
_lock_file = "/tmp/subprocess_asgi_server.lock"
_port_range = range(8000, 9000)

def __new__(cls, port: Optional[int] = None, *args, **kwargs):
Expand Down Expand Up @@ -775,10 +773,9 @@ def __init__(self, port: Optional[int] = None):
def find_available_port(self):
max_attempts = 10
for _ in range(max_attempts):
with FileLock(self._lock_file):
port = random.choice(self._port_range)
if self.is_port_available(port):
return port
port = random.choice(self._port_range)
if self.is_port_available(port):
return port
time.sleep(random.uniform(0.1, 0.5)) # Random backoff
raise RuntimeError("Unable to find an available port after multiple attempts")

Expand Down

0 comments on commit 0415d96

Please sign in to comment.