~paulliu/friends/add-twitter-contacts

« back to all changes in this revision

Viewing changes to friends/main.py

  • Committer: Robert Bruce Park
  • Date: 2012-11-04 19:30:57 UTC
  • Revision ID: robert.park@canonical.com-20121104193057-cvpb72ylbra0r0d2
Do lazy loading of Yappi module.

This optional performance profiling module is unlikely to be used by
anybody but me, so there's no point having everybody else load it by
default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
from friends.utils.model import prune_model
43
43
from friends.utils.options import Options
44
44
 
 
45
 
45
46
# Optional performance profiling module.
46
47
yappi = None
47
 
try:
48
 
    import yappi
49
 
except ImportError:
50
 
    pass
51
48
 
52
49
 
53
50
# Logger must be initialized before it can be used.
67
64
            print(class_name)
68
65
        return
69
66
 
70
 
    do_profiling = args.performance and yappi is not None
71
 
 
72
 
    if do_profiling:
73
 
        yappi.start()
 
67
    if args.performance:
 
68
        try:
 
69
            import yappi
 
70
        except ImportError:
 
71
            pass
 
72
        else:
 
73
            yappi.start()
74
74
 
75
75
    # Initialize the logging subsystem.
76
76
    gsettings = Gio.Settings.new('com.canonical.friends')
123
123
    except KeyboardInterrupt:
124
124
        log.info('Stopped friends-service main loop')
125
125
 
126
 
    if do_profiling:
 
126
    if args.performance and yappi is not None:
127
127
        yappi.print_stats(sys.stdout, yappi.SORTTYPE_TTOT)
128
128
 
129
129