第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Streamlit - 在線程中創(chuàng)建的 SQLite 對象只能在同一個線程中使用

Streamlit - 在線程中創(chuàng)建的 SQLite 對象只能在同一個線程中使用

侃侃爾雅 2022-12-06 14:57:49
我使用Streamlit作為我的數(shù)據(jù)處理和可視化框架。按照關(guān)于使用 Streamlit 進行高級緩存的文檔,關(guān)于如何創(chuàng)建數(shù)據(jù)庫連接并將它們傳遞給其他函數(shù),我正在使用sqlite3并嘗試在運行時創(chuàng)建一個連接并傳遞“光標”,方法是:import streamlit as st# create database connection@st.cache(allow_output_mutation=True)def get_database_connection():    conn = sqlite3.connect('collect/Data/fpl.db')    c = conn.cursor()       return c在這里,我嘗試通過 傳遞我的連接 ID hash_funcs,返回創(chuàng)建的游標:# pass connections around@st.cache(allow_output_mutation=True, hash_funcs={sqlite3.Cursor:id})def get_teams_basic(c):    df_teams = sql('SELECT * FROM TeamsBasic', c)    return df_teams@st.cache(allow_output_mutation=True, hash_funcs={sqlite3.Cursor:id})def get_players_basic(c):       df_player_basic = sql('SELECT * FROM PlayersBasic', c)    return df_player_basic# and so on...這是我的sql():def sql(query, cursor):    '''    Takes an SQL query string, and outputs a    dataframe representation of the query result.    '''    # Execute the sql query    cursor.execute(query)    # Get the query into a dataframe and set columns    df_temp = pd.DataFrame(cursor.fetchall())    df_temp.columns = [x[0] for x in cursor.description]    # Set the sql id as the dataframe index    index_column = df_temp.columns[0]    df_temp.set_index(index_column, drop=True, inplace=True)    return df_temp然后,在 處main(),我實例化數(shù)據(jù)庫連接并將光標傳遞給我的函數(shù):def main():    c = get_database_connection()    teams(c)    players(c)if __name__ == '__main__':  main()但是當(dāng)代碼到達第二個連接時,players()出現(xiàn)以下錯誤:ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 123145444151296 and this is thread id 123145454661632.我錯過了什么?
查看完整描述

1 回答

?
心有法竹

TA貢獻1866條經(jīng)驗 獲得超5個贊

我不確定您是否仍在解決這個問題,但如果您還在,我發(fā)現(xiàn)了一個可能有用的關(guān)于該主題的討論線程。我很快就會在我的一個項目中試用它。

https://discuss.streamlit.io/t/prediction-analysis-and-creating-a-database/3504


查看完整回答
反對 回復(fù) 2022-12-06
  • 1 回答
  • 0 關(guān)注
  • 537 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號