Don't use global variable profiledir
Rather than setting a global threadutil/profiledir variable, we make set_profiledir a class function that sets the class variable profiledir. While touching theprofiledir code, add warning to the user if the profile directory existed before. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
8970a1500b
commit
642880b404
@ -1,6 +1,5 @@
|
||||
# OfflineIMAP initialization code
|
||||
# Copyright (C) 2002-2007 John Goerzen
|
||||
# <jgoerzen@complete.org>
|
||||
# Copyright (C) 2002-2011 John Goerzen & contributors
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -157,11 +156,14 @@ class OfflineImap:
|
||||
if not options.singlethreading:
|
||||
logging.warn("Profile mode: Forcing to singlethreaded.")
|
||||
options.singlethreading = True
|
||||
profiledir = options.profiledir
|
||||
os.mkdir(profiledir)
|
||||
threadutil.setprofiledir(profiledir)
|
||||
if os.path.exists(options.profiledir):
|
||||
logging.warn("Profile mode: Directory '%s' already exists!" %
|
||||
options.profiledir)
|
||||
else:
|
||||
os.mkdir(options.profiledir)
|
||||
threadutil.ExitNotifyThread.set_profiledir(options.profiledir)
|
||||
logging.warn("Profile mode: Potentially large data will be "
|
||||
"created in '%s'" % profiledir)
|
||||
"created in '%s'" % options.profiledir)
|
||||
|
||||
#override a config value
|
||||
if options.configoverride:
|
||||
|
@ -1,6 +1,5 @@
|
||||
# Copyright (C) 2002, 2003 John Goerzen
|
||||
# Copyright (C) 2002-2011 John Goerzen & contributors
|
||||
# Thread support module
|
||||
# <jgoerzen@complete.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -20,15 +19,10 @@ from threading import Lock, Thread, BoundedSemaphore
|
||||
from Queue import Queue, Empty
|
||||
import traceback
|
||||
from thread import get_ident # python < 2.6 support
|
||||
import os.path
|
||||
import sys
|
||||
from offlineimap.ui import getglobalui
|
||||
|
||||
profiledir = None
|
||||
|
||||
def setprofiledir(newdir):
|
||||
global profiledir
|
||||
profiledir = newdir
|
||||
|
||||
######################################################################
|
||||
# General utilities
|
||||
######################################################################
|
||||
@ -132,11 +126,14 @@ def threadexited(thread):
|
||||
class ExitNotifyThread(Thread):
|
||||
"""This class is designed to alert a "monitor" to the fact that a thread has
|
||||
exited and to provide for the ability for it to find out why."""
|
||||
profiledir = None
|
||||
"""class variable that is set to the profile directory if required"""
|
||||
|
||||
def run(self):
|
||||
global exitthreads, profiledir
|
||||
global exitthreads
|
||||
self.threadid = get_ident()
|
||||
try:
|
||||
if not profiledir: # normal case
|
||||
if not ExitNotifyThread.profiledir: # normal case
|
||||
Thread.run(self)
|
||||
else:
|
||||
try:
|
||||
@ -148,9 +145,8 @@ class ExitNotifyThread(Thread):
|
||||
prof = prof.runctx("Thread.run(self)", globals(), locals())
|
||||
except SystemExit:
|
||||
pass
|
||||
prof.dump_stats( \
|
||||
profiledir + "/" + str(self.threadid) + "_" + \
|
||||
self.getName() + ".prof")
|
||||
prof.dump_stats(os.path.join(ExitNotifyThread.profiledir,
|
||||
"%s_%s.prof" % (self.threadid, self.getName())))
|
||||
except:
|
||||
self.setExitCause('EXCEPTION')
|
||||
if sys:
|
||||
@ -194,7 +190,12 @@ class ExitNotifyThread(Thread):
|
||||
a call to setExitMessage(), or None if there was no such message
|
||||
set."""
|
||||
return self.exitmessage
|
||||
|
||||
|
||||
@classmethod
|
||||
def set_profiledir(cls, directory):
|
||||
"""If set, will output profile information to 'directory'"""
|
||||
cls.profiledir = directory
|
||||
|
||||
|
||||
######################################################################
|
||||
# Instance-limited threads
|
||||
|
Loading…
Reference in New Issue
Block a user