0

そのため、SQLite データベースから大量のデータを取得するコードを実行すると、

Python コードで次のエラーが発生します。

(<type 'exceptions.MemoryError'>, 'main.py', 427)

はい、上記の例外は、私自身のエラー形式の一部です。

印刷する前はMemoryError

これは私が427行目に持っているものです:

rows=cur.fetchall()

次に、問題はメモリに関係していると想定しました。したがって、次のことを行いました

sqlite> PRAGMA page_size = 1073741824;
sqlite> PRAGMA cache_size = 100000;
sqlite> VACUUM;


sqlite> PRAGMA page_size;
4096
Memory Used:                         50186800 (max 100373936) bytes
Number of Outstanding Allocations:   12075 (max 24216)
Number of Pcache Overflow Bytes:     50045536 (max 100095168) bytes
Number of Scratch Overflow Bytes:    0 (max 11392) bytes
Largest Allocation:                  469214 bytes
Largest Pcache Allocation:           4244 bytes
Largest Scratch Allocation:          11392 bytes
Lookaside Slots Used:                0 (max 0)
Successful lookaside attempts:       0
Lookaside failures due to size:      0
Lookaside failures due to OOM:       0
Pager Heap Usage:                    49904696 bytes
Page cache hits:                     2011
Page cache misses:                   21561
Page cache writes:                   11780
Schema Heap Usage:                   7296 bytes
Statement Heap/Lookaside Usage:      1448 bytes
Fullscan Steps:                      0
Sort Operations:                     0
Autoindex Inserts:                   0
sqlite>


sqlite> .version
SQLite 3.7.13 2012-06-11 02:05:22

しかし、私はまだ同じエラーが発生します。

考え?

編集:

答えの打撃ごとに、試みた:

rows = []
while True:
   rows.append(cur.fetchone())

でも同じ結果。

4

1 に答える 1

2

データベース ファイルのサイズは、クエリによって返されるすべてのレコードのサイズと必ずしも関連しているわけではありません。

fetchallすべての結果を一度にメモリにロードする必要があります。fetchone繰り返し電話して、レコードを個別に処理する方がよいでしょう。

于 2013-07-23T13:56:14.390 に答える