Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

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 April 21st, 2004, 11:38 AM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 185 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
files over the web

I have a python script that saves info to a .csv file. If two or more ppl are trying to access it the same time will the file lock and prevent one from opening and submitting to it or does it not matter beacuse of the client/server architecture of the webbrowser?
is there a way to circumvent this in python perhaps catching the exception?
do i HAVE TO use a relational database to circumvent this problem? Please say no.
__________________
"In theory, there is no difference between theory and practice.
But, in practice, there is."


Reply With Quote
  #2  
Old April 22nd, 2004, 09:39 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
I can't really test this right now but in theory the file should be locked - two file streams can't write to the file at the same time, or if they do your file gets wiped.

Your earlier post might be relivant here too - http://forums.devshed.com/t140081/s.html

You could always try locking the file manually just to be sure.

Another way to do this would be to check if the file is accessable using os.access() although i havn't used this at all:

http://www.python.org/doc/2.3.3/lib/os-file-dir.html

You should also be able to use a try-except block to check if a file is writeable or not.

All options to consider, hope this helps.

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old April 22nd, 2004, 10:21 PM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 185 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
Thanks for the reply. Sorry about the double post. I didn't receive an email telling me anyone had responded. I think i might just have to use a rdms. Thanks.

Reply With Quote
  #4  
Old April 23rd, 2004, 01:31 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Thats ok, not a problem at all. You might want to look at PySQLite for small projects where you really dont need to use MySQL although MySQL is ideal for web applications IMO.

Even if the current DBI is a little long winded for my tastes; again just an oppinion .

Mark.

Reply With Quote
  #5  
Old April 23rd, 2004, 10:02 AM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 185 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
actaully was thinking about using sqlite. i had just read up on it and it said there was some things that still were not implemented. i'll check it out again. by the way sql lite can hold up to 2 terabytes of info. That is pretty significant. unless other databases hold more. never used a db before.

Reply With Quote
  #6  
Old April 23rd, 2004, 04:16 PM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 185 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
okay, i had the txt file opened and then i went online and wrote in the form to see if i would get an error when i submitted to the same file. however the infomation was submitted to the file still. does that mean that the file isn't locked and two or more ppl can submit at the same time. I'm really not expecting a lot of traffic on the site. or did i test it wrong.?

Reply With Quote
  #7  
Old April 23rd, 2004, 06:02 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
Just because you open a file to read or write does not mean you have a lock on it. There are OS specific ways to get a file lock at the system level.
Doing a search for python file lock threw up this:
http://aspn.activestate.com/ASPN/Co...on/Recipe/65203

From what you say - it's not going to be a problem in practice. Just write the logging code in some function. That way if you ever have to upgrade your logging you just change the core of the function.

Grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #8  
Old April 24th, 2004, 11:12 AM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 185 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
for now i just want multiple users to write to the files so i'll just save it as .txt and have it comma delimited then i look at it, i'll save it as a csv file. that'll be easier for me - for now. later i'll look into implementing a database. Still weird how a csv file will lock and a text file won't.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > files over the web

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap