mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Since tempfiles seem to occasionally be left behind, allow logging of
open tempfiles, including a traceback (to determine callers) if LOG_TEMPFILES is set in the environment when Galaxy starts. This should be considered temporary and will be removed when it's determined where/how this happens.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# override tempfile methods for debugging
|
||||
|
||||
import tempfile, traceback
|
||||
|
||||
import logging
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
class TempFile( object ):
|
||||
def __init__( self ):
|
||||
tempfile._NamedTemporaryFile = tempfile.NamedTemporaryFile
|
||||
tempfile._mkstemp = tempfile.mkstemp
|
||||
tempfile.NamedTemporaryFile = self.NamedTemporaryFile
|
||||
tempfile.mkstemp = self.mkstemp
|
||||
def NamedTemporaryFile( self, *args, **kwargs ):
|
||||
f = tempfile._NamedTemporaryFile( *args, **kwargs )
|
||||
try:
|
||||
log.debug( ( "Opened tempfile %s with NamedTemporaryFile:\n" % f.name ) + "".join( traceback.format_stack() ) )
|
||||
except AttributeError:
|
||||
pass
|
||||
return f
|
||||
def mkstemp( self, *args, **kwargs ):
|
||||
f = tempfile._mkstemp( *args, **kwargs )
|
||||
try:
|
||||
log.debug( ( "Opened tempfile %s with mkstemp:\n" % f[1] ) + "".join( traceback.format_stack() ) )
|
||||
except TypeError:
|
||||
pass
|
||||
return f
|
||||
@@ -16,6 +16,11 @@ sys.path = new_path
|
||||
from galaxy import eggs
|
||||
import pkg_resources
|
||||
|
||||
if 'LOG_TEMPFILES' in os.environ:
|
||||
from log_tempfile import TempFile
|
||||
_log_tempfile = TempFile()
|
||||
import tempfile
|
||||
|
||||
pkg_resources.require( "PasteScript" )
|
||||
|
||||
from paste.script import command
|
||||
|
||||
Reference in New Issue
Block a user