Exemplo n.º 1
0
from scavenger import Scavenger
from time import sleep, time

sleep(1.2)

peers = Scavenger.get_peers()
for peer in peers:
    print peer
if len(peers) != 0:
    print 'start'
    start = time()
    print Scavenger.perform_service(peers[0], 'daimi.test.add', {'x':1, 'y':1}, timeout=2)
    print 'done - elapsed =', time()-start
    
    print 'installing service'
    start = time()
    if not Scavenger.has_service(peers[0], 'daimi.test.subtract'):
        Scavenger.install_service(peers[0], 'daimi.test.subtract',"""
def perform(x, y):
    z = 0
    for v in range(0,100000):
        z += v
    return x - y
""")
    print 'done - elapsed =', time()-start
    
    print 'start'
    start = time()
    print Scavenger.perform_service(peers[0], 'daimi.test.subtract', {'x':1, 'y':1}, timeout=2)
    print 'done - elapsed =', time()-start
    
Exemplo n.º 2
0
# Sleep for a little while to make sure that we discover
# the available surrogates.
sleep(2.0)

# Place the input data at the chosen peer.
peers = Scavenger.get_peers()
found_him = False
for peer in peers:
    if peer.name == spiked_peer:
        found_him = True
        if not Scavenger.has_service(peer, 'std.rdh.store'):
            Scavenger.install_service(peer, 'std.rdh.store', """
def perform(image):
    return image
""")
        data_handle = Scavenger.perform_service(peer, 'std.rdh.store', {'image':image}, store=True)
        data_handle.retain = True
        Scavenger.retain_data(data_handle)
        print 'just got spiked!'
if not found_him:
    raise Exception('Unable to find the peer')

@scavenger.scavenge
def sharpen(image, factor):
    from PIL import Image, ImageEnhance
    from StringIO import StringIO
    sio = StringIO(image)
    pil_image = Image.open(sio)
    factor = 1.0 + float(factor)
    sharpened_image = ImageEnhance.Sharpness(pil_image).enhance(factor)
    sio = StringIO()