[Spambayes-checkins] spambayes/scripts sb_filter.py,1.19,1.20

Skip Montanaro montanaro at users.sourceforge.net
Sun Aug 6 16:50:32 CEST 2006


Update of /cvsroot/spambayes/spambayes/scripts
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv19924

Modified Files:
	sb_filter.py 
Log Message:
Run under control of the new cProfile profiler, if it's available.  I found
this useful to help identify where SB spends its time while training.


Index: sb_filter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_filter.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** sb_filter.py	7 Apr 2006 02:25:25 -0000	1.19
--- sb_filter.py	6 Aug 2006 14:50:29 -0000	1.20
***************
*** 47,50 ****
--- 47,53 ----
          set [section, option] in the options database to value
  
+     -P
+         Run under control of the Python profiler, if it is available
+ 
  All options marked with '*' operate on stdin, and write the resultant
  message to stdout.
***************
*** 211,220 ****
          self.h.store()
  
! def main():
      h = HammieFilter()
      actions = []
!     opts, args = getopt.getopt(sys.argv[1:], 'hvxd:p:nfgstGSo:',
                                 ['help', 'version', 'examples', 'option='])
      create_newdb = False
      for opt, arg in opts:
          if opt in ('-h', '--help'):
--- 214,224 ----
          self.h.store()
  
! def main(profiling=False):
      h = HammieFilter()
      actions = []
!     opts, args = getopt.getopt(sys.argv[1:], 'hvxd:p:nfgstGSo:P',
                                 ['help', 'version', 'examples', 'option='])
      create_newdb = False
+     do_profile = False
      for opt, arg in opts:
          if opt in ('-h', '--help'):
***************
*** 238,241 ****
--- 242,254 ----
          elif opt == '-S':
              actions.append(h.untrain_spam)
+         elif opt == '-P':
+             do_profile = True
+             if not profiling:
+                 try:
+                     import cProfile
+                 except ImportError:
+                     pass
+                 else:
+                     return cProfile.run("main(True)")
          elif opt == "-n":
              create_newdb = True



More information about the Spambayes-checkins mailing list