Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming
View Poll Results: How to handle database write colisions
Persistant Database Writer 1 50.00%
Non-persistant Database Writer 0 0%
Protected Section / Mutex 1 50.00%
Neither see my post belo 0 0%
Voters: 2. You may not vote on this poll


Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2004, 09:06 AM
MBirchmeier's Avatar
MBirchmeier MBirchmeier is offline
I <3 ASCII
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Wishing i was still at... The Ohio State University
Posts: 2,272 MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 h 12 m 48 sec
Reputation Power: 838
Send a message via AIM to MBirchmeier Send a message via Yahoo to MBirchmeier
Multithreading with Python and ODBC

All-

I'm designing (well debugging to be specific) a server program that parses through files and either adds or alters a database to include the file information. For speed and maintenance issues this is multithreaded.

We have the same instance of the ODBC present throughout all threads (because we had trouble creating seperate ODBC instances for the different threads)

Now the problem occurred when attempting to write to the database. Each thread had it's own ODBC cursor, but when two (or more) threads attempted to write to the database at the same time python crashed.

Now there's three ways I can think of to avoid this, and an option incase there's a better way.

1.) Have a persistant 'database writer' thread and we pass / pipe messages to that process to write the database.

2.) Have a non-persistant 'database writer' thread and we open it up to write to the database, this would have a maximum thread count of 1 to avoid colisions

3.) We have a protected section around all database writes so that only one item can write at a time.

4.) Do something else moron see my post for how to really do it

Please vote
__________________
My blog on programming related things. Hopefully I won't bog it down with details on my life

Apparently even computers have freudian slips.

0x4279 7465 204D 6521

Reply With Quote
  #2  
Old November 9th, 2004, 06:48 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
I would have a single database thread, and a queue of objects to write to the database. Any thread can push objects to the queue, which will block if the queue is full. The database thread takes objects off the queue and writes them to the database, and will wait if the queue is empty.

See the Queue module in the Python library for full details.

Dave - The Developers' Coach

Reply With Quote
  #3  
Old November 12th, 2004, 08:57 AM
MBirchmeier's Avatar
MBirchmeier MBirchmeier is offline
I <3 ASCII
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Wishing i was still at... The Ohio State University
Posts: 2,272 MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level)MBirchmeier User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 h 12 m 48 sec
Reputation Power: 838
Send a message via AIM to MBirchmeier Send a message via Yahoo to MBirchmeier
Thanks for the responses...

I ended up going with a protected section, since the code was already developed and tearing it all up would have been more of a hassle than a savings.

In the future though I'll probablly stick with a persistant database writer thread that the other thread pass messages to.

-MBirchmeier

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Multithreading with Python and ODBC


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT