Scott Chapman wrote:
>I'm using 3.0.0 b2 for this.
>
>def connect(thread_index):
> cherrypy.thread_data.thread_index = thread_index
> if not hasattr(cherrypy.thread_data,'db'):
> cherrypy.thread_data.db = {}
> cherrypy.thread_data.db[thread_index] =
apsw.Connection("C:/foo/db.db3")
>
>cherrypy.engine.on_start_thread_list.append(connect)
>
>def disconnect(thread_index):
> if hasattr(cherrypy.thread_data,'db'):
> cherrypy.thread_data.db[thread_index].close()
>
>cherrypy.engine.on_stop_thread_list.append(disconnect)
>
>I can use the db connection in my code just fine like
this:
>cursor =
cherrypy.thread_data.db[cherrypy.thread_data.thread_index].c
ursor()
>
>But when I Ctrl-C the web server, I get tons of these:
>
>Exception apsw.ThreadingViolationError: 'The destructor
for Connection is
>called in a different thread than it was created in.
All calls must be in the
>same thread. It was created in thread 3496and this is
3600. This SQLite
>database is not being closed as a result.' in
<apsw.Connection object at
>0x00D58138>
>
>Why? I'm closing the thread for the db connection for
the given thread_index.
> I can't figure it out.
>
Because all of the on_stop_thread_list functions are called
from the
main thread, NOT from the thread whose index is being passed
to you.
I'm not sure there is any way for you to get a shutdown
notification in
the context of each thread.
--
Tim Roberts, timr probo.com
Providenza & Boekelheide, Inc.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---
|