diff options
| author | 2010-10-07 13:11:07 +0200 | |
|---|---|---|
| committer | 2010-10-07 13:11:07 +0200 | |
| commit | 11c80f1d4985b21b5800b981428f7bf88fa9778b (patch) | |
| tree | d1b66ae141541b3ff1b8e23139e7faa249c2cdde | |
| parent | unrar ram check (diff) | |
| download | pyload-11c80f1d4985b21b5800b981428f7bf88fa9778b.tar.xz | |
recycle sqlite connection
| -rw-r--r-- | module/FileDatabase.py | 19 | ||||
| -rw-r--r-- | module/ThreadManager.py | 4 | ||||
| -rwxr-xr-x | module/network/Request.py | 2 | ||||
| -rw-r--r-- | module/plugins/Plugin.py | 6 | 
4 files changed, 23 insertions, 8 deletions
diff --git a/module/FileDatabase.py b/module/FileDatabase.py index 6e6537f38..4bcb63764 100644 --- a/module/FileDatabase.py +++ b/module/FileDatabase.py @@ -562,15 +562,17 @@ class FileDatabaseBackend(Thread):          self.c = self.conn.cursor()          #self.c.execute("PRAGMA synchronous = OFF")          self._createTables() -        self.c.close() + +        self.used = 0          while True:              try:                  f, args, async = self.jobs.get() +                self.used += 1                  if f == "quit": return True -                self.c = self.conn.cursor() +                if self.used > 300:    #recycle connection +                    self.recycleConnection()                  res = f(*args) -                self.c.close()                  if not async: self.res.put(res)              except Exception, e:                  #@TODO log etc @@ -582,6 +584,17 @@ class FileDatabaseBackend(Thread):          self.syncSave()          self.jobs.put(("quit", "", 0)) +    def recycleConnection(self): +        self.manager.core.log.debug("Recycle sqlite connection") +        self.conn.commit() +        self.c.close() +        self.conn.close() +        del self.c +        del self.conn +        self.conn = sqlite3.connect("files.db") +        self.c = self.conn.cursor() +        self.used = 0 +      def _checkVersion(self):          """ check db version and delete it if needed"""          if not exists("files.version"): diff --git a/module/ThreadManager.py b/module/ThreadManager.py index 19e239c16..73e9efe56 100644 --- a/module/ThreadManager.py +++ b/module/ThreadManager.py @@ -172,12 +172,12 @@ class ThreadManager:          if self.pause or not self.core.server_methods.is_time_download(): return          if self.downloaded > 20: -            if self.downloadingIds(): +            if self.downloadingIds() or self.processingIds():                  return              pycurl.global_cleanup()              pycurl.global_init(pycurl.GLOBAL_DEFAULT)              self.downloaded = 0 -            self.log.debug("Cleaned up resources") +            self.log.debug("Cleaned up pycurl")          free = [x for x in self.threads if not x.active] diff --git a/module/network/Request.py b/module/network/Request.py index c0551b042..9c711a02c 100755 --- a/module/network/Request.py +++ b/module/network/Request.py @@ -309,7 +309,7 @@ class Request:          #@TODO content disposition -        #return free_name +        return free_name      def updateCurrentSpeed(self, speed):          self.dl_speed = speed diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index 55faa37e1..bfe10845d 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -31,6 +31,7 @@ from os import chmod  from os import stat  from os.path import exists  from os.path import join +from os.path import basename  if os.name != "nt":      from os import chown @@ -296,13 +297,14 @@ class Plugin(object):          name = self.pyfile.name.encode(sys.getfilesystemencoding(), "replace")          newname = self.req.download(url, name, location, get, post, ref, cookies) - +        newname = basename(newname) +                  self.pyfile.size = self.req.dl_size          if newname and newname != name:              self.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname})              name = newname -            self.pyfile.name = newname +            #self.pyfile.name = newname          if self.core.config["permission"]["change_file"]:              chmod(join(location, name), int(self.core.config["permission"]["file"],8))  | 
