にアクセスしたときにクラッシュすると、正常に動作し、簡単なスレッドプログラムです:Pythonのスレッド - 彼らはここpostgreSQLの
import psycopg2
import threading
import time
class testit(threading.Thread):
def __init__(self, currency):
threading.Thread.__init__(self)
self.currency = currency
def run(self):
global SQLConnection
global cursor
SQLString = "Select dval from ddata where dname ='%s' and ddate = '2009-07-17'" \
%self.currency
z = time.time()
while (time.time() - z) < 2:
print SQLString
SQLConnection = psycopg2.connect(database = "db", user = "xxxx", password = "xxxx")
cursor = SQLConnection.cursor()
a = testit('EURCZK')
b = testit('EURPLN')
a.start()
b.start()
しかし、すぐに私は次のコードでスレッドでのPostgreSQLデータベースにアクセスして起動しようとして、私はいつも
import psycopg2
import threading
import time
class testit(threading.Thread):
def __init__(self, currency):
threading.Thread.__init__(self)
self.currency = currency
def run(self):
global SQLConnection
global cursor
SQLString = "Select dval from ddata where dname ='%s'and ddate = '2009-07-17'" %self.currency
z = time.time()
while (time.time() - z) < 2:
cursor.execute(SQLString)
print cursor.fetchall()
SQLConnection = psycopg2.connect(database = "db", user = "xxxx", password = "xxxx")
cursor = SQLConnection.cursor()
a = testit('EURCZK')
b = testit('EURPLN')
a.start()
b.start()
唯一の違いはwhileループです。私はスレッドプログラミングにかなり新しいです。 postgresライブラリ(psycopg2)は "スレッドセーフ"ではありませんか?これはすべてWindows XP上で実行されています。私は何でもできる?
ありがとうございました。
psycopgこれを行うことができます。正確なエラーメッセージは何ですか? – Christopher
エラーメッセージが表示されません。クリストファー - 大きなウィンドウが表示され、メモリの一部の場所を読み取ることができません。したがって、適切なシステムレベルのクラッシュが発生します。私は各スレッドに独自の接続とカーソルを与えようとします。 –
ハァッ。はい。まあ、http://www.free-soft.org/FSM/english/issue01/fog.htmlは、元の試行が有効だったことを示しています。おそらくこれはv2で変更されました。 – Christopher