2009-11-10, 05:11
bmillham Wrote:I've been trying to get Persistence working with a MySQL connection. Sadly, it doesn't look like Persistence is up to the task yet.
Code:import ClassHandler
handler = ClassHandler.ClassHandler()
db = MySQLdb.connect(host='tardis', user='root', passwd='', db='mynewmovies')
handler.save(db)
Results in
Code:22:10:06 T:140196460296256 M:846225408 DEBUG: ------ Window Init (DialogKaiToast.xml) ------
22:10:06 T:140196460296256 M:846225408 DEBUG: Alloc resources: 0.01ms (0.00 ms skin load)
22:10:07 T:140196033116432 M:846225408 INFO: Python script stopped
22:10:07 T:140196033116432 M:846225408 DEBUG: Thread 140196033116432 terminating
22:10:07 T:140196149074192 M:846225408 NOTICE: Traceback (most recent call last):
22:10:07 T:140196149074192 M:846225408 NOTICE: File "/home/brian/.xbmc/scripts/Persistence/Persistence.py", line 65, in ?
22:10:07 T:140196149074192 M:846225408 NOTICE: server = ClassServer()
22:10:07 T:140196149074192 M:846225408 NOTICE: File "/home/brian/.xbmc/scripts/Persistence/Persistence.py", line 12, in __init__
22:10:07 T:140196149074192 M:846225408 NOTICE: self.connect()
22:10:07 T:140196149074192 M:846225408 NOTICE: File "/home/brian/.xbmc/scripts/Persistence/Persistence.py", line 27, in connect
22:10:07 T:140196460296256 M:846225408 DEBUG: python thread 8 destructed
22:10:07 T:140196149074192 M:846225408 NOTICE: self.processCommand(clientsock, clientaddr)
22:10:07 T:140196149074192 M:846225408 NOTICE: File "/home/brian/.xbmc/scripts/Persistence/Persistence.py", line 43, in processCommand
22:10:07 T:140196149074192 M:846225408 NOTICE: classInstance = comm.recv(clientsock)
22:10:07 T:140196149074192 M:846225408 NOTICE: File "/home/brian/.xbmc/scripts/Persistence/comm.py", line 24, in recv
22:10:07 T:140196149074192 M:846225408 NOTICE: datasize = unpack("<i", sock.recv(4))[0]
22:10:07 T:140196149074192 M:846225408 NOTICE: struct
22:10:07 T:140196149074192 M:846225408 NOTICE: .
22:10:07 T:140196149074192 M:846225408 NOTICE: error
22:10:07 T:140196149074192 M:846225408 NOTICE: :
22:10:07 T:140196149074192 M:846225408 NOTICE: unpack str size does not match format
22:10:07 T:140196149074192 M:846225408 ERROR: Scriptresult: Error
22:10:07 T:140196460296256 M:846225408 DEBUG: WaitOnScriptResult - plugin exited prematurely - terminating
I've tried various different ways like:
Code:classInstance = handler.exists(MySQLdb.connect) or handler.new(MySQLdb.connect, ('tardis', '3306', 'root', '', 'mynewmovies'))
with similar results. (one strange difference is the error would vary from expecting a str when using 3306 as the port to expecting an int when using '3306'
Oh well, looked like a nice idea, but I'm going to continue on working on my script instead of a plugin.
(BTW: I doubt that it matters, but I'm running 9.11alpha1. I did try the example supplied with Persistence, and it works fine)
Brian
I've looked at this some more, and it looks like the problem is with cPickle.
I tried a script from command line:
Code:
>>> c = MySQLdb.connect(host='tardis', port=3306, user='root', passwd='', db='mynewmovies')
>>> p = cPickle.dumps(c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/copy_reg.py", line 71, in _reduce_ex
state = base(self)
TypeError: connect() argument 1 must be string, not Connection
>>>
Can someone give me a pointer about how to solve this, or pointers to where in the Python world where I may get some help?
Thanks again!
Brian