def save_list( self ): if not ( self.is_job_running and len( self.activity_reg ) > 0 ): sys.exit( "no jobs registered." ) print 'finishing the last job' if self.is_job_running: self.end_job() print "activity %s ended at %s"% (str(self.activity_reg[self.job_no-1][0]),str (self.activity_reg[self.job_no-1][2])) job_list='# activity code | start time | end time | {duration hours}.{duration minutes} (in base 10)\n' total_hours =0 total_minutes=0 for job_item in self.activity_reg: if self.debug_mode: pdb.set_trace() try: job_list += str(job_item[0])+'|'+str(job_item[1])+'|'+str(job_item[2])+'|'+'%s%s'%( str( self.interval ( [job_item[3], job_item[4] ]) ), os.linesep ) except IndexError: sys.exit( "no activities were registered, exiting." ) if os.path.exists( self.out_file ): #output file already exists, lazyboy have not yet implemented append, so I make new file for you, cheap. sfh = open(self.out_file+str(time.time()), 'w') else: sfh = open(self.out_file,'w') sfh.write(job_list) print 'saved activities into file', self.out_file sfh.close()
def depth_disconts2(di, tol=0.2): import pydb pydb.set_trace() import scipy.ndimage as ndimage ndimage.gaussian_filter(di, sigma=(5, 5)) ndimage.gaussian_derivative() ndimage.median_filter() return di_diff
def myfunction(string,sleeptime,lock,*args): while 1: #entering critical section pydb.set_trace(add_threaddbg=True) lock.acquire() print string," Now Sleeping after Lock acquired for ",sleeptime time.sleep(sleeptime) print string," Now releasing lock and then sleeping again" lock.release() #exiting critical section time.sleep(sleeptime) # why?
def myfunction(string, sleeptime, lock, *args): while 1: #entering critical section pydb.set_trace(add_threaddbg=True) lock.acquire() print string, " Now Sleeping after Lock acquired for ", sleeptime time.sleep(sleeptime) print string, " Now releasing lock and then sleeping again" lock.release() #exiting critical section time.sleep(sleeptime) # why?
def list_vars(locdict, Stop, tail_msg=''): if '_var_defaults' in locdict: print('\n===== Input variables, and their default values ' '(from _var_defaults) ======') print(locdict['_var_defaults']) # check the global namespace too - can't see _var_defaults when # running with "run -i" (but it hasn't helped). if _var_defaults in globals(): print('\n=========== Variables, and default values =========') print(globals()['_var_defaults']) else: _user_locals=[] for v in locdict: if (v.find('_')!=0 and str(locdict[v]).find('function')<0 and str(locdict[v]).find('module')<0): _user_locals.append(v) print('\n========= Accessible variables and current values are: =====') #, _user_locals) if verbose > 0: _n=0 for k in _user_locals: print(" %s = %s" % (k, locdict[k])) _n +=1 if (_n==20): # was raw_input for python2 - hopefully siz.moves works for python2/3 ans=input('do you want to see the rest of the local vars? (y/N/Q) ') if ans.upper()=='Q': _sys.exit() elif ans.upper()!='Y': print(ans) break if _rhs != None and _rhs != "None": if not _rhs in locdict: print('RHS < {rhs} > is not in local dictionary - if you wish to refer to ' 'a variable from the working interactive namespace, then ' 'use the -i option (under ipython only)'.format(rhs=_rhs)) # Note: pydb is nicer but slower.... if Stop: print('======== make sure there are *NO SPACES* - e.g. x=123 not x = 123 ======') if tail_msg !='': print(tail_msg) ans=input(' q or ^C (+<CR>) to stop? ') # raw_input still needs a CR if ans.upper() == 'Q': _sys.exit() return() # I thought I didn't know how to just "stop" - maybe the above works try: import pydb; pydb.set_trace('s','print "set vars, c to continue"') except: print('unable to load pydb, using pdb') import pdb; pdb.set_trace() 'c to continue, or s for one step, then enter the var name manually '
def generate_dotcode(selected_names = [], depth = 3, excludes = [], with_stacks = False): if depth is None: depth = -1 gen = Generator(selected_names = selected_names, depth = depth, excludes = excludes, with_stacks = with_stacks) graph = gen.generate() import pydb; pydb.set_trace() dot = graph.create_dot() # sadly pydot generates line wraps cutting between numbers return dot.replace("\\\n", "")
def list_vars(locdict, Stop): if locdict.has_key('_var_defaults'): print('\n=========== Variables, and default values =========') print(locdict['_var_defaults']) # check the global namespace too - can't see _var_default when # running with "run -i" (but it hasn't helped). if globals().has_key('_var_defaults'): print('\n=========== Variables, and default values =========') print(globals()['_var_defaults']) else: _user_locals = [] for v in locdict: if (v.find('_') != 0 and str(locdict[v]).find('function') < 0 and str(locdict[v]).find('module') < 0): _user_locals.append(v) print '\n========= Accessible variables and current values are: =====' #, _user_locals if verbose > 0: _n = 0 for k in _user_locals: print(" %s = %s" % (k, locdict[k])) _n += 1 if (_n == 20): ans = raw_input( 'do you want to see the rest of the local vars? (y/N) ' ) if ans.upper() != 'Y': print(ans) break if _rhs != None: if not (locdict.has_key(_rhs)): print(( 'RHS < %s > is not in local dictionary - if you wish to refer to ' 'a variable from the working interactive namespace, then ' 'use the -i option (under ipython only)') % _rhs) # Note: pydb is nicer but slower.... if Stop: print( '======== make sure there are no spaces - e.g. x=123 not x = 123 ======' ) ans = raw_input(' ^C to stop') return () # don't know how to just "stop" try: import pydb pydb.set_trace('s', 'print "set vars, c to continue"') except: print('unable to load pydb, using pdb') import pdb pdb.set_trace() 'c to continue, or s for one step, then enter the var name manually '
def generate_dotcode(selected_names=[], depth=3, excludes=[], with_stacks=False): if depth is None: depth = -1 gen = Generator(selected_names=selected_names, depth=depth, excludes=excludes, with_stacks=with_stacks) graph = gen.generate() import pydb pydb.set_trace() dot = graph.create_dot() # sadly pydot generates line wraps cutting between numbers return dot.replace("\\\n", "")
def list_vars(locdict, Stop): if locdict.has_key('_var_defaults'): print('\n=========== Variables, and default values =========') print(locdict['_var_defaults']) # check the global namespace too - can't see _var_default when # running with "run -i" (but it hasn't helped). if globals().has_key('_var_defaults'): print('\n=========== Variables, and default values =========') print(globals()['_var_defaults']) else: _user_locals=[] for v in locdict: if (v.find('_')!=0 and str(locdict[v]).find('function')<0 and str(locdict[v]).find('module')<0): _user_locals.append(v) print '\n========= Accessible variables and current values are: =====' #, _user_locals if verbose>0: _n=0 for k in _user_locals: print(" %s = %s" % (k, locdict[k])) _n +=1 if (_n==20): ans=raw_input('do you want to see the rest of the local vars? (y/N) ') if ans.upper()!='Y': print(ans) break if _rhs != None: if not(locdict.has_key(_rhs)): print(('RHS < %s > is not in local dictionary - if you wish to refer to ' 'a variable from the working interactive namespace, then ' 'use the -i option (under ipython only)') % _rhs) # Note: pydb is nicer but slower.... if Stop: print('======== make sure there are no spaces - e.g. x=123 not x = 123 ======') ans=raw_input(' ^C to stop') return() # don't know how to just "stop" try: import pydb; pydb.set_trace('s','print "set vars, c to continue"') except: print('unable to load pydb, using pdb') import pdb; pdb.set_trace() 'c to continue, or s for one step, then enter the var name manually '
def interval( self, epoch_list ): """ computes the interval between two epoch timestamps and returns the difference expressed in base 10 hours. Eg. 2 hours 30 minutes == 2.50 interval expects two epoch timestamps, but in this doctest, we're faking it in order to be able to actually understand the values >>> c = timereg( 'txt' ) >>> c.interval( [ time.mktime((2008, 2, 4, 20, 14, 25, 0, 35, 0)), time.mktime((2008, 2, 4, 22, 44, 25, 0, 35, 0)) ] ) '2.50' >>> c.interval( [ time.mktime((2008, 2, 4, 20, 14, 25, 0, 35, 0)), time.mktime((2008, 2, 4, 20, 35, 25, 0, 35, 0)) ] ) '0.35' >>> c.interval( [ time.mktime((2008, 2, 4, 20, 14, 25, 0, 35, 0)), time.mktime((2008, 2, 4, 20, 44, 25, 0, 35, 0)) ] ) '0.50' >>> c.interval( [ time.mktime((2008, 2, 4, 20, 14, 25, 0, 35, 0)), time.mktime((2008, 2, 5, 22, 14, 25, 0, 36, 0)) ] ) '26.00' """ if self.debug_mode: pdb.set_trace() secs = float(time.mktime(time.localtime( epoch_list[1] - epoch_list[0] ) ) ) #the return float hours in base 10 return '%.2f'%(float(secs / 60 / 60))
def list_vars(locdict, Stop, tail_msg=''): if '_var_defaults' in locdict: print('\n===== Input variables, and their default values ' '(from _var_defaults) ======') print(locdict['_var_defaults']) # check the global namespace too - can't see _var_defaults when # running with "run -i" (but it hasn't helped). if '_var_defaults' in globals(): print('\n=========== Variables, and default values =========') print(globals()['_var_defaults']) else: _user_locals = [] for v in locdict: if (v.find('_') != 0 and str(locdict[v]).find('function') < 0 and str(locdict[v]).find('module') < 0): _user_locals.append(v) print('\n========= Accessible variables and current values are: =====' ) #, _user_locals) if verbose > 0: print('locals............') _n = 0 for k in _user_locals: print(" %s = %s" % (k, locdict[k])) _n += 1 if (_n == 20): # was raw_input for python2 - six.moves works for python2/3 ans = input( 'do you want to see the rest of the local vars? (y/N/Q) ' ) if ans.upper() == 'Q': _sys.exit() elif ans.upper() != 'Y': print(ans) break if _rhs != None and _rhs != "None": if not _rhs in locdict: print( 'RHS < {rhs} > is not in local dictionary - if you wish to refer to ' 'a variable from the working interactive namespace, then ' 'use the -i option (under ipython only)'.format(rhs=_rhs)) # Note: pydb is nicer but slower.... if Stop: print( '======== make sure there are *NO SPACES* - e.g. x=123 not x = 123 ======' ) if tail_msg != '': print(tail_msg) ans = input(' q or ^C (+<CR>) to stop? ') # raw_input still needs a CR if ans.upper() == 'Q': _sys.exit() return ( ) # I thought I didn't know how to just "stop" - maybe the above works try: import pydb pydb.set_trace('s', 'print "set vars, c to continue"') except: print('unable to load pydb, using pdb') import pdb pdb.set_trace() 'c to continue, or s for one step, then enter the var name manually '
def test(): # Force a call to the debugger in running code here pydb.set_trace()