# HG changeset patch # User Oleg Oshmyan # Date 1275429425 0 # Node ID c0e925ae721e3e92bb0706d5afdeeb0d6fd62c24 # Parent 28b1f48539687ad8ff348f7ee8e1856d3fdd99d0 Flush stdout during update; initial work on memory usage control diff -r 28b1f4853968 -r c0e925ae721e test-svn.py --- a/test-svn.py Sat Mar 13 00:04:57 2010 +0000 +++ b/test-svn.py Tue Jun 01 21:57:05 2010 +0000 @@ -14,11 +14,24 @@ parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed when finished testing') parser.add_option('-p', '--python', action='store_true', default=False, help='always parse all positional arguments as a single Python expression (including the first argument even if it names an executable file)') parser.add_option('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function') +parser.add_option('-b', dest='builtin', action='store_true', default=False) options, args = parser.parse_args() parser.destroy() del parser +if options.builtin: + try: + if args[0] == 'run': + import resource + maxmemory = int(args[1]) + resource.setrlimit(resource.RLIMIT_AS, (maxmemory*1024**2, maxmemory*1024**2)) + os.execv(args[2], args[2:]) + else: + sys.exit(2) + except: + sys.exit(2) + def update(): import urllib latesttext = urllib.urlopen('http://chortos.selfip.net/~astiob/test.py/version.txt').read() @@ -40,6 +53,7 @@ print 'Your copy of test.py is newer than the publicly available version.' return print 'A ' + update + ' update to test.py is available. Downloading...' + sys.stdout.flush() urllib.urlretrieve('http://chortos.selfip.net/~astiob/test.py/test.py', 'test.py') print 'Downloaded and installed. Now you are using test.py ' + latesttext + '.' @@ -47,6 +61,19 @@ update() sys.exit() +try: + import resource + memlimit = True + def call(name): + pid = os.fork() + if not pid: + resource.setrlimit(resource.RLIMIT_AS, (maxmemory*1024**2, maxmemory*1024**2)) + os.execl(name) + else: + return pid +except ImportError: + memlimit = False + globals1 = set(globals()) # Initialize some configuration variables with default values