Poor interaction with threads (python 2.7)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 28/100
Direzione di ricerca
Inizia con il file query.txt allegato e con il punto di ingresso GraphQLView.get_context mostrato nell’esempio, quindi traccia dummy_middleware, i resolver annidati, promise.async_instance e Flask g attraverso richieste concorrenti. Riproduci il problema con l’esempio Python 2.7 fornito e determina dove l’esecuzione cambia thread. Il lavoro è concluso quando l’interazione è compresa ed è stata concordata una direzione correttiva per preservare il contesto locale della richiesta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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]))
- Lingua principale
- Python
- Stelle
- 1.3k
- Fork
- 139
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di graphql-python/flask-graphql
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
graphql-python/flask-graphql#92 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
graphql-python/flask-graphql#85 · 2 commenti · 1 reazione ·
-
CSRF Exemption? Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
graphql-python/flask-graphql#84 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
graphql-python/flask-graphql#80 · 9 commenti · 2 reazioni ·
Tutte le issue di graphql-python/flask-graphql
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
anthropics/skills#1811 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
speaches-ai/speaches#678 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
datalayer/mcp-compose#42 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
UKGovernmentBEIS/inspect_evals#2523 ·