Changeset 5927
- Timestamp:
- Aug 15, 2007, 4:10:37 PM (17 years ago)
- Location:
- trunk/trac
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/trac/env.py
r5909 r5927 1 1 # -*- coding: utf-8 -*- 2 2 # 3 # Copyright (C) 2003-200 5Edgewall Software4 # Copyright (C) 2003-200 5Jonas Borgström <jonas@edgewall.com>3 # Copyright (C) 2003-2007 Edgewall Software 4 # Copyright (C) 2003-2007 Jonas Borgström <jonas@edgewall.com> 5 5 # All rights reserved. 6 6 # … … 16 16 17 17 import os 18 try: 19 import threading 20 except ImportError: 21 import dummy_threading as threading 22 import setuptools 18 23 import sys 19 24 from urlparse import urlsplit 20 21 import setuptools22 25 23 26 from trac import db_default … … 488 491 489 492 490 def open_environment(env_path=None): 493 env_cache = {} 494 env_cache_lock = threading.Lock() 495 496 def open_environment(env_path=None, use_cache=False): 491 497 """Open an existing environment object, and verify that the database is up 492 498 to date. 493 499 494 @param: env_path absolute path to the environment directory; if ommitted, 495 the value of the `TRAC_ENV` environment variable is used 500 @param env_path: absolute path to the environment directory; if ommitted, 501 the value of the `TRAC_ENV` environment variable is used 502 @param use_cache: whether the environment should be cached for subsequent 503 invocations of this function 496 504 @return: the `Environment` object 497 505 """ 506 global env_cache, env_cache_lock 507 498 508 if not env_path: 499 509 env_path = os.getenv('TRAC_ENV') … … 503 513 'Trac environment.') 504 514 505 env = Environment(env_path) 506 needs_upgrade = False 507 try: 508 needs_upgrade = env.needs_upgrade() 509 except Exception, e: # e.g. no database connection 510 env.log.exception(e) 511 raise TracError("The Trac Environment couldn't check for upgrade. " 512 + str(e)) 513 if needs_upgrade: 514 raise TracError('The Trac Environment needs to be upgraded.\n\n' 515 'Run "trac-admin %s upgrade"' % env_path) 515 if use_cache: 516 env_cache_lock.acquire() 517 try: 518 env = env_cache.get(env_path) 519 if env is None: 520 env = env_cache.setdefault(env_path, open_environment(env_path)) 521 else: 522 # Re-parse the configuration file if it changed since the last 523 # the time it was parsed 524 env.config.parse_if_needed() 525 finally: 526 env_cache_lock.release() 527 else: 528 env = Environment(env_path) 529 needs_upgrade = False 530 try: 531 needs_upgrade = env.needs_upgrade() 532 except Exception, e: # e.g. no database connection 533 env.log.exception(e) 534 if needs_upgrade: 535 raise TracError('The Trac Environment needs to be upgraded.\n\n' 536 'Run "trac-admin %s upgrade"' % env_path) 537 516 538 return env -
trunk/trac/web/main.py
r5864 r5927 1 1 # -*- coding: utf-8 -*- 2 2 # 3 # Copyright (C) 2005 Edgewall Software4 # Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>3 # Copyright (C) 2005-2007 Edgewall Software 4 # Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de> 5 5 # Copyright (C) 2005 Matthew Good <trac@matt-good.net> 6 6 # All rights reserved. … … 23 23 import pkg_resources 24 24 import sys 25 try: 26 import threading 27 except ImportError: 28 import dummy_threading as threading 25 29 26 30 from genshi import Markup … … 42 46 from trac.web.href import Href 43 47 from trac.web.session import Session 44 45 # Environment cache for multithreaded front-ends:46 try:47 import threading48 except ImportError:49 import dummy_threading as threading50 51 env_cache = {}52 env_cache_lock = threading.Lock()53 54 def _open_environment(env_path, run_once=False):55 if run_once:56 return open_environment(env_path)57 58 global env_cache, env_cache_lock59 env = None60 env_cache_lock.acquire()61 try:62 if not env_path in env_cache:63 env_cache[env_path] = open_environment(env_path)64 env = env_cache[env_path]65 finally:66 env_cache_lock.release()67 68 # Re-parse the configuration file if it changed since the last the time it69 # was parsed70 env.config.parse_if_needed()71 72 return env73 48 74 49 def populate_hdf(hdf, env, req=None): … … 391 366 env = env_error = None 392 367 try: 393 env = _open_environment(env_path, run_once=run_once)368 env = open_environment(env_path, use_cache=not run_once) 394 369 if env.base_url: 395 370 environ['trac.base_url'] = env.base_url … … 512 487 for env_name, env_path in get_environments(environ).items(): 513 488 try: 514 env = _open_environment(env_path,515 run_once=environ['wsgi.run_once'])489 env = open_environment(env_path, 490 use_cache=not environ['wsgi.run_once']) 516 491 proj = { 517 492 'name': env.project_name, -
trunk/trac/web/modpython_frontend.py
r5865 r5927 1 1 # -*- coding: utf-8 -*- 2 2 # 3 # Copyright (C) 2004-200 5Edgewall Software4 # Copyright (C) 2004-200 5Christopher Lenz <cmlenz@gmx.de>3 # Copyright (C) 2004-2007 Edgewall Software 4 # Copyright (C) 2004-2007 Christopher Lenz <cmlenz@gmx.de> 5 5 # Copyright (C) 2005 Matthew Good <trac@matt-good.net> 6 6 # All rights reserved.
Note:
See TracChangeset
for help on using the changeset viewer.