我正在使用Mastermind pygame库,我正在尝试从服务器发送和接收数据。
错误看起来像这样;
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python33\lib\threading.py", line 637, in _bootstrap_inner
self.run()
File "C:\Python33\lib\threading.py", line 594, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Kevin\Dropbox\Python\PythonRPG-Server\Mastermind\_mm_server.py", line 219, in run_forever
self.server.callback_client_handle(self,data)
File "server.py", line 54, in callback_client_handle
register = self.db.register(data[1]['username'], data[1]['username'])
File "C:\Users\Kevin\Dropbox\Python\PythonRPG-Server\db.py", line 148, in register
self.saveDB()
File "C:\Users\Kevin\Dropbox\Python\PythonRPG-Server\db.py", line 126, in saveDB
self.conn.commit()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 5072 and this is thread id 976
寄存器功能是;
def register(self, user, password):
"""
Register user to database
"""
###Check if user exists
query = "SELECT password FROM accounts WHERE username = '%s';" % (user)
qure = self.query(query)
if not qure:
hashe = sha256_crypt.encrypt(password)
sql = "INSERT INTO acounts (username, password) values('%s', '%s');" % (user, hashe)
self.query(sql)
self.saveDB()
message = "New user: " + user
#alertMessageDialog(msg=message, title='Created!')
return True
elif qure:
#alertMessageDialog(msg='User already exists', title='User exists')
return False
#cur.execute("INSERT INTO users (username, password) VALUES (%s, %s)" % (user, hashe))
#print(sha256_crypt.verify("password", hashe))
#print(hashe)
起初我以为我在服务器上创建了多个实例,但这仍然不会影响线程。那么,可能出现什么问题呢?我之前从未使用过线程,所以我完全被难倒了。我现在甚至不想使用线程,但我正在使用的库使用它...