Ben zaman aşımı dönen bir SQL Simya uygulama var:SQL Simya QueuePool sınırı taşma
Ben oturumu kapatmak yok ama eğer bilmiyorsanız bu durumla farklı bir yazı okumakTimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30
iki fonksiyonlarda bazı verileri toplama ama başlatıldı DBSession kullanıyorum başka piton dosyasında Sonra
from .dbmodels import (
DBSession,
Base,
engine = create_engine("mysql://" + loadConfigVar("user") + ":" + loadConfigVar("password") + "@" + loadConfigVar("host") + "/" + loadConfigVar("schema"))
#Sets the engine to the session and the Base model class
DBSession.configure(bind=engine)
Base.metadata.bind = engine
: Ben init.py içinde veritabanına bağlanmak
: bu benim koduna geçerlidir init.py içinde:
from .dbmodels import DBSession
from .dbmodels import resourcestatsModel
def getFeaturedGroups(max = 1):
try:
#Get the number of download per resource
transaction.commit()
rescount = DBSession.connection().execute("select resource_id,count(resource_id) as total FROM resourcestats")
#Move the data to an array
resources = []
data = {}
for row in rescount:
data["resource_id"] = row.resource_id
data["total"] = row.total
resources.append(data)
#Get the list of groups
group_list = toolkit.get_action('group_list')({}, {})
for group in group_list:
#Get the details of each group
group_info = toolkit.get_action('group_show')({}, {'id': group})
#Count the features of the group
addFesturedCount(resources,group,group_info)
#Order the FeaturedGroups by total
FeaturedGroups.sort(key=lambda x: x["total"],reverse=True)
print FeaturedGroups
#Move the data of the group to the result array.
result = []
count = 0
for group in FeaturedGroups:
group_info = toolkit.get_action('group_show')({}, {'id': group["group_id"]})
result.append(group_info)
count = count +1
if count == max:
break
return result
except:
return []
def getResourceStats(resourceID):
transaction.commit()
return DBSession.query(resourcestatsModel).filter_by(resource_id = resourceID).count()
oturum değişkenleri şöyle oluşturulur: oturum init.py içinde benim de bunu kullanmak sonraki kodda oluşturulan
#Basic SQLAlchemy types
from sqlalchemy import (
Column,
Text,
DateTime,
Integer,
ForeignKey
)
# Use SQLAlchemy declarative type
from sqlalchemy.ext.declarative import declarative_base
#
from sqlalchemy.orm import (
scoped_session,
sessionmaker,
)
#Use Zope' sqlalchemy transaction manager
from zope.sqlalchemy import ZopeTransactionExtension
#Main plugin session
DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Çünkü; hangi noktada oturumu kapatmalıyım? Ya da havuz boyutunu yönetmek için başka ne yapmam gerekiyor?
Sen parametreler ekleyerek havuzu boyutunu yönetebilir
İkinci kod snippet'inde, i "İşlem" tanımlandı mı? –
'getResourceStats' nerede kullanılır? Kodun yarısı eksik gibi görünüyor - hepsini ekleyebilir veya sorunu teşhis etmek imkansız olabilir. –
Bu kod, olduğu gibi çalışıyor mu? @TomDalton tarafından belirtilen konulara ek olarak 'import' ifadesi gerçekten garip görünüyor. Hata hangi noktada ortaya çıkıyor? Bu [Minimal, Tam, Doğrulanabilir örnek] (http://stackoverflow.com/help/mcve)? IOW, bunu (ya da önemli ölçüde) azaltabilir ve yine de aynı davranışı sergileyebilir misiniz? Orada bir çok iş mantığı var gibi görünüyor, bu sorunun sebebi pek olası değil. Bunu kaldırmayı ve tam bir çalışma (sözdizimsel olarak doğru) örneği göndermeyi deneyin, ve size yardımcı olmaktan mutluluk duyarız. – cod3monk3y