From 3f62e1d302fb63f1f3c5c72121388c8b0dd6e784 Mon Sep 17 00:00:00 2001 From: "Krzysztof A. Adamski" Date: Fri, 6 Jun 2008 18:08:26 -0400 Subject: Fixing "modulus voodoo". --- func/forkbomb.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'func/forkbomb.py') diff --git a/func/forkbomb.py b/func/forkbomb.py index b835d3d..7cc9df3 100644 --- a/func/forkbomb.py +++ b/func/forkbomb.py @@ -75,8 +75,8 @@ def __bucketize(pool, slots): buckets = {} count = 0 for key in pool: - count = count + 1 slot = count % slots + count = count + 1 if not buckets.has_key(slot): buckets[slot] = [] buckets[slot].append(key) @@ -130,9 +130,9 @@ def batch_run(pool,callback,nforks=DEFAULT_FORKS,cachedir=DEFAULT_CACHE_DIR): the workload over nfork forks. Temporary files used during the operation will be created in cachedir and subsequently deleted. """ - if nforks <= 1: + if nforks < 1: # modulus voodoo gets crazy otherwise and bad things happen - nforks = 2 + nforks = 1 shelf_file = __get_storage(cachedir) __access_buckets(shelf_file,True,None) buckets = __bucketize(pool, nforks) -- cgit From bb80b6e6f10bd97b2926f447e913d8249592c32d Mon Sep 17 00:00:00 2001 From: "Krzysztof A. Adamski" Date: Sat, 7 Jun 2008 15:03:27 -0400 Subject: Change bsddb which is leaking on new python versions. --- func/forkbomb.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'func/forkbomb.py') diff --git a/func/forkbomb.py b/func/forkbomb.py index 7cc9df3..ef0817a 100644 --- a/func/forkbomb.py +++ b/func/forkbomb.py @@ -16,7 +16,7 @@ import os import random # for testing only import time # for testing only import shelve -import bsddb +import dbm import sys import tempfile import fcntl @@ -39,10 +39,10 @@ def __access_buckets(filename,clear,new_key=None,new_value=None): modifying it as required. """ - internal_db = bsddb.btopen(filename, 'c', 0644 ) - handle = open(filename,"r") + handle = open(filename,"w") fcntl.flock(handle.fileno(), fcntl.LOCK_EX) - storage = shelve.BsdDbShelf(internal_db) + internal_db = dbm.open(filename, 'c', 0644 ) + storage = shelve.Shelf(internal_db) if clear: storage.clear() @@ -138,7 +138,14 @@ def batch_run(pool,callback,nforks=DEFAULT_FORKS,cachedir=DEFAULT_CACHE_DIR): buckets = __bucketize(pool, nforks) __forkbomb(0,buckets,callback,shelf_file) rc = __access_buckets(shelf_file,False,None) - os.remove(shelf_file) + + try: #it's only cleanup so don't care if the files disapeared + os.remove(shelf_file) + os.remove(shelf_file+".pag") + os.remove(shelf_file+".dir") + except OSError: + pass + return rc def __test(nforks=4,sample_size=20): -- cgit