Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle multiprocessing forks in _EventLoopSingleton #1373

Merged
merged 13 commits into from
Nov 1, 2024

Conversation

tsmith023
Copy link
Collaborator

@tsmith023 tsmith023 commented Oct 30, 2024

Closes #1309

MRE to reproduce, courtesy of @gariel ❤️

import logging
import os

from fastapi import FastAPI
from fastapi.responses import JSONResponse

from pydantic import BaseModel
import weaviate
from weaviate.classes.query import Filter


# some dependency instantiate a sync client on import/file root
client = weaviate.connect_to_local()
client.close()

app = FastAPI()
logger = logging.getLogger(__name__)

class StatusBody(BaseModel):
    collection: str
    field: str
    value: str


@app.post("/sync", response_class=JSONResponse)
async def status_sync(body: StatusBody):
    logger.info("Status endpoint")

    with weaviate.connect_to_local() as client:

        logger.info("Status got client")

        result = client.collections.get(body.collection).query.fetch_objects(
            filters=Filter.by_property(body.field).equal(body.value),
            limit=1
        )

        logger.info("Status got response")

        data = result.objects[0].properties
        logger.info(f"Status: {data}")

        return data


if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=80)

and run:
gunicorn --bind=0.0.0.0:80 --workers=2 --worker-class "uvicorn.workers.UvicornWorker" --preload main:app

@tsmith023 tsmith023 requested a review from dirkkul October 30, 2024 13:06
@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 93.94%. Comparing base (3f68082) to head (d44a585).
Report is 146 commits behind head on main.

Files with missing lines Patch % Lines
weaviate/event_loop.py 73.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1373      +/-   ##
==========================================
- Coverage   94.38%   93.94%   -0.44%     
==========================================
  Files         220      221       +1     
  Lines       20956    21283     +327     
==========================================
+ Hits        19779    19995     +216     
- Misses       1177     1288     +111     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dirkkul dirkkul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test? :)

@weaviate-git-bot
Copy link

Great to see you again! Thanks for the contribution.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Slack channel?

@tsmith023 tsmith023 requested a review from a team as a code owner October 31, 2024 16:47
@tsmith023 tsmith023 requested a review from dirkkul October 31, 2024 16:47
@dirkkul dirkkul merged commit 7bbe81b into main Nov 1, 2024
42 of 44 checks passed
@dirkkul dirkkul deleted the event-loop/fix-hanging-due-to-multiprocessing branch November 1, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem upgrading to version higher than 4.6.7 on AWS ECS Cluster
4 participants