Poor interaction with threads (python 2.7)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 28/100
Hướng nghiên cứu
Bắt đầu với query.txt đính kèm và entry point GraphQLView.get_context được hiển thị trong ví dụ, sau đó truy vết dummy_middleware, các resolver lồng nhau, promise.async_instance và Flask g qua các request đồng thời. Tái hiện lỗi bằng ví dụ Python 2.7 được cung cấp và xác định nơi execution chuyển thread. Được xem là hoàn tất khi đã hiểu interaction và thống nhất được hướng khắc phục để duy trì context cục bộ của request.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
the interaction between this library, graphql-core, and promise appears to allow execution to hop threads especially (only?) when using a middleware and nested resolvers. this is inconsistent with flasks threading model and the ability to access the request/g thread locals
with the attached (very contrived) example, when submitting the query with concurrent requests the requests frequently fail because the key created in get_context doesn't exist on the threadlocal flask.g object in the resolvers. This happens when a thread accesses the promise.async_instance which isn't thread local, and resolves a promise that was created on a different thread.
query.txt
from flask import Flask
from flask_graphql import GraphQLView
app = Flask(__name__)
import graphene
import threading
import time
from flask import g
def get_user(info):
return g.get(info.context['key'])
class User(graphene.ObjectType):
id = graphene.ID()
name = graphene.String()
friend = graphene.Field(lambda: User)
age = graphene.Int()
apple = graphene.String()
@classmethod
def resolve_friend(cls, root, info):
time.sleep(.1)
x = get_user(info)
return User(id=id(root), name=':'.join([x.name, threading.current_thread().name]))
@classmethod
def resolve_age(cls, root, info):
time.sleep(.1)
return 5
@classmethod
def resolve_apple(cls, root, info):
time.sleep(.1)
return "Apple"
class Query(graphene.ObjectType):
me = graphene.Field(User)
def resolve_me(self, info):
time.sleep(.1)
return get_user(info)
schema = graphene.Schema(query=Query)
ahh = {}
def dummy_middleware(next, root, info, **args):
return_value = next(root, info, **args)
return return_value
import random
random.seed()
class TestQLView(GraphQLView):
def get_context(self, request):
# set a random key in g to be used by resolvers
key = str(random.randint(0,50))
name = threading.current_thread().name
user = User(id=key, name=name)
setattr(g, key, user)
return {
'key': key
}
app.add_url_rule('/graphql', view_func=TestQLView.as_view('graphql', schema=schema, graphiql=True, middleware=[dummy_middleware]))
- Ngôn ngữ chính
- Python
- Star
- 1.3k
- Fork
- 139
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của graphql-python/flask-graphql
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
graphql-python/flask-graphql#92 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
-
which graphiql version is using? Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
graphql-python/flask-graphql#85 · 2 bình luận · 1 reaction ·
-
CSRF Exemption? Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
graphql-python/flask-graphql#84 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
graphql-python/flask-graphql#80 · 9 bình luận · 2 reaction ·
Tất cả issue của graphql-python/flask-graphql
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
anthropics/skills#1811 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
speaches-ai/speaches#678 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
datalayer/mcp-compose#42 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
conda-forge/spacy-feedstock#177 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
UKGovernmentBEIS/inspect_evals#2523 ·