List Info

Thread: Why do I get Threading Violation's with this db.close()?




Why do I get Threading Violation's with this db.close()?
user name
2006-10-03 19:33:33
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.

Scott

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Why do I get Threading Violation's with this db.close()?
user name
2006-10-03 20:27:18
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, timrprobo.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-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

Why do I get Threading Violation's with this db.close()?
user name
2006-10-03 20:52:14
Tim Roberts wrote:

> 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.

Then how are people handling the closing of databases when
their applications 
shut down?

Scott

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )