[PATCH] Import cProfile module before falling back to profile

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Dec 6 12:19:31 UTC 2010


the cProfile/profile modules are great for performance debugging. The
pure-python profile module has much more overhead though and the
cProfile module is recommended if it exists. This changes to import to
first try the cProfile module and then fall back to the profile
module. The cProfile/profiles modules are API compatible for all that
its worth...

If that does not exist we continue to complain as before.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/threadutil.py |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/offlineimap/threadutil.py b/offlineimap/threadutil.py
index b516f68..c65700e 100644
--- a/offlineimap/threadutil.py
+++ b/offlineimap/threadutil.py
@@ -148,7 +148,10 @@ class ExitNotifyThread(Thread):
             if not profiledir:          # normal case
                 Thread.run(self)
             else:
-                import profile
+                try:
+                    import cProfile as profile
+                except ImportError:
+                    import profile
                 prof = profile.Profile()
                 try:
                     prof = prof.runctx("Thread.run(self)", globals(), locals())
-- 
1.7.1




More information about the OfflineIMAP-project mailing list