def upkeep(): """Does upkeep (like flushing, garbage collection, etc.)""" sys.exc_clear() # Just in case, let's clear the exception info. if os.name == 'nt': try: import msvcrt msvcrt.heapmin() except ImportError: pass except IOError: # Win98 sux0rs! pass if conf.daemonized: # If we're daemonized, sys.stdout has been replaced with a StringIO # object, so let's see if anything's been printed, and if so, let's # log.warning it (things shouldn't be printed, and we're more likely # to get bug reports if we make it a warning). assert not type(sys.stdout) == file, 'Not a StringIO object!' if not hasattr(sys.stdout, 'getvalue'): # Stupid twisted sometimes replaces our stdout with theirs, because # "The Twisted Way Is The Right Way" (ha!). So we're stuck simply # returning. log.warning('Expected cStringIO as stdout, got %r.', sys.stdout) return s = sys.stdout.getvalue() if s: log.warning('Printed to stdout after daemonization: %s', s) sys.stdout.reset() # Seeks to 0. sys.stdout.truncate() # Truncates to current offset. assert not type(sys.stderr) == file, 'Not a StringIO object!' s = sys.stderr.getvalue() if s: log.error('Printed to stderr after daemonization: %s', s) sys.stderr.reset() # Seeks to 0. sys.stderr.truncate() # Truncates to current offset. doFlush = conf.supybot.flush() and not starting if doFlush: flush() # This is so registry._cache gets filled. # This seems dumb, so we'll try not doing it anymore. #if registryFilename is not None: # registry.open(registryFilename) if not dying: log.debug('Regexp cache size: %s', len(sre._cache)) log.debug('Pattern cache size: %s', len(ircutils._patternCache)) log.debug('HostmaskPatternEqual cache size: %s', len(ircutils._hostmaskPatternEqualCache)) #timestamp = log.timestamp() if doFlush: log.info('Flushers flushed and garbage collected.') else: log.info('Garbage collected.') collected = gc.collect() if gc.garbage: log.warning( 'Noncollectable garbage (file this as a bug on SF.net): %s', gc.garbage) return collected
def upkeep(): """Does upkeep (like flushing, garbage collection, etc.)""" sys.exc_clear() # Just in case, let's clear the exception info. if os.name == 'nt': try: import msvcrt msvcrt.heapmin() except ImportError: pass except IOError: # Win98 sux0rs! pass if conf.daemonized: # If we're daemonized, sys.stdout has been replaced with a StringIO # object, so let's see if anything's been printed, and if so, let's # log.warning it (things shouldn't be printed, and we're more likely # to get bug reports if we make it a warning). assert not type(sys.stdout) == file, 'Not a StringIO object!' if not hasattr(sys.stdout, 'getvalue'): # Stupid twisted sometimes replaces our stdout with theirs, because # "The Twisted Way Is The Right Way" (ha!). So we're stuck simply # returning. log.warning('Expected cStringIO as stdout, got %r.', sys.stdout) return s = sys.stdout.getvalue() if s: log.warning('Printed to stdout after daemonization: %s', s) sys.stdout.reset() # Seeks to 0. sys.stdout.truncate() # Truncates to current offset. assert not type(sys.stderr) == file, 'Not a StringIO object!' s = sys.stderr.getvalue() if s: log.error('Printed to stderr after daemonization: %s', s) sys.stderr.reset() # Seeks to 0. sys.stderr.truncate() # Truncates to current offset. doFlush = conf.supybot.flush() and not starting if doFlush: flush() # This is so registry._cache gets filled. # This seems dumb, so we'll try not doing it anymore. #if registryFilename is not None: # registry.open(registryFilename) if not dying: log.debug('Regexp cache size: %s', len(sre._cache)) log.debug('Pattern cache size: %s', len(ircutils._patternCache)) log.debug('HostmaskPatternEqual cache size: %s', len(ircutils._hostmaskPatternEqualCache)) #timestamp = log.timestamp() if doFlush: log.info('Flushers flushed and garbage collected.') else: log.info('Garbage collected.') collected = gc.collect() if gc.garbage: log.warning('Noncollectable garbage (file this as a bug on SF.net): %s', gc.garbage) return collected
def upkeep(): try: threading.Timer(360, upkeep).start() except: delivery(u'Внимание! Командуй --> "exec threading.Timer(360, upkeep).start()"') sys.exc_clear() if BOT_OS == 'nt': import msvcrt; msvcrt.heapmin() gc.collect() if MEMORY_LIMIT and memory_usage() >= MEMORY_LIMIT: sys_exit('memory leak')
def upkeep(): tmr=threading.Timer(60, upkeep) tmr.start() sys.exc_clear() if os.name == 'nt': try: import msvcrt msvcrt.heapmin() except: pass import gc gc.collect()
def upkeep(): tmr = threading.Timer(60, upkeep) tmr.start() sys.exc_clear() if os.name == 'nt': try: import msvcrt msvcrt.heapmin() except: pass import gc gc.collect()
## Type n for new recording, Type x to exit if msvcrt.kbhit(): presskey = msvcrt.getwch() if presskey == 'n': print("============================================================================") print("New round of recording") del_num = del_num + 1 csvfile.close() csvfile = open('data%s.csv' % del_num, 'w', newline='') filewrite = csv.writer(csvfile) filewrite.writerow( ['B1S1X', 'B1S1Y', 'B1S1Z', 'B1S2X', 'B1S2Y', 'B1S2Z', 'B1S3X', 'B1S3Y', 'B1S3Z', 'B1S4X', 'B1S4Y', 'B1S4Z', 'B2S1X', 'B2S1Y', 'B2S1Z', 'B2S2X', 'B2S2Y', 'B2S2Z', 'B2S3X', 'B2S3Y', 'B2S3Z', 'B2S4X', 'B2S4Y', 'B2S4Z', 'B3S1X', 'B3S1Y', 'B3S1Z', 'B3S2X', 'B3S2Y', 'B3S2Z', 'B3S3X', 'B3S3Y', 'B3S3Z', 'B3S4X', 'B3S4Y', 'B3S4Z', 'B4S1X', 'B4S1Y', 'B4S1Z', 'B4S2X', 'B4S2Y', 'B4S2Z', 'B4S3X', 'B4S3Y', 'B4S3Z', 'B4S4X', 'B4S4Y', 'B4S4Z']) print("Csv File 'data%s' Created" % del_num) print('Recording data...') if presskey == 'x': sys.exit() msvcrt.heapmin() presskey = 'N\A' csvfile.close() ser.close()