Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 20th, 2006, 8:25 AM   #21
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Okay, since I can at least understand my code, giving potential to changes therein, I'll stick with it. Thanks though.
Sane is offline   Reply With Quote
Old Feb 20th, 2006, 4:20 PM   #22
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Why are you rejecting it? A superior solution has been offered that will run much faster, take up less space, and leave less room for error. If you can't understand it, just ask and it'll be explained.
Cerulean is offline   Reply With Quote
Old Feb 20th, 2006, 5:10 PM   #23
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Well I felt like I have been pestering Arevos. >_> Which I have.

And it's not necessarily "superior", speed will be different by approximately 1/1 000 000th of a second. And if I understand it, I can at least make changes as seen necessary. @_@

I've implemented my system and it seems to be working fine, working 10 threads. I had to do two differen locking systems though, an extra for the dynamic images. I couldn't have stats being written to the image that's being downloaded by someone.
Sane is offline   Reply With Quote
Old Feb 20th, 2006, 6:24 PM   #24
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
If Sane's just saving and loading images, which I suspect he is, he'll probably only need to read or write to a file once before it is closed, so his solution isn't likely to be particularly less efficient than mine.

I think my way's neater - and as Cerulean says, it's a little more robust. But there's a lot to be said for working out a solution on your own, and if Sane's careful, he's not going to run into any problems with his solution.
Quote:
Originally Posted by Sane
I've implemented my system and it seems to be working fine, working 10 threads. I had to do two differen locking systems though, an extra for the dynamic images. I couldn't have stats being written to the image that's being downloaded by someone.
That's good news! Though what do you mean by "two different locking systems" - you mean two caches, or just two ways of using the same cache?
Arevos is offline   Reply With Quote
Old Feb 20th, 2006, 7:49 PM   #25
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Nah, just one system that I posted up above, and then a seperate lock for locking the block of code that creates and serves the dynamic image.



Edit:

Wow, I'm happy I noticed this!! =]

I had a used except IOError in some places to except if the file didn't exist. But in my function it raises the IOError without ever releasing the lock. This was creating a huge problem in my site, the biggest being you couldn't log in if you hadn't already with the same IP.

    def read(self):
        lock = FileReadWriteLock(self.fname)

        lock.acquire_read()
        try:
            file = open(self.fname, self.ftype)
            data = file.read()
            file.close()
        except IOError:
            lock.release_read()
            raise IOError
        
        return data

    def readlines(self):
        lock = FileReadWriteLock(self.fname)

        lock.acquire_read()
        try:
            file = open(self.fname, self.ftype)
            data = file.readlines()
            file.close()
        except IOError:
            lock.release_read()
            raise IOError

        return data

Fixed ^^

Last edited by Sane; Feb 20th, 2006 at 8:13 PM.
Sane is offline   Reply With Quote
Old Feb 20th, 2006, 8:22 PM   #26
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,835
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Post Edit:
I forgot the "lock.release_read()" after the IOError except. >___>;;; I feel so dumb.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC