Python Forum
Tuple Space with lindypy Problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tuple Space with lindypy Problem
#1
Can someone please explain why I only get this output? I have this example code from lindypy documents and I only get the output below which was not expected.

import os
import time
from lindypy import *

def worker(ts):
    print 'worker', os.getpid(), 'start'
    while True:
        # we are interested in any tuple of four integers
        t = ts.inp((int, int, int, int))
        print 'worker', os.getpid(), 'data <-', t
        # this pretends some complex calculation
        time.sleep(1.0)
        # now grab the sum tuple and update it
        s = ts.inp(('sum', object))
        print 'worker', os.getpid(), 'sum <-', t
        ts.out(('sum', s[1]+sum(t)))
        print 'worker', os.getpid(), '-> sum', s[1]+sum(t)

def breaking_worker(ts):
    raise ValueError(55)

with tuplespace() as ts:
    # seed the tuple space with the sum tuple
    ts.out(('sum', 0))

    # start all the workers
    for i in range(5):
        ts.eval(worker)

    # push some tuples of integers into the tuple space
    ts.out((1,2,3,4))
    ts.out((4,5,6,7))
    ts.out((3,4,5,2))

    # lets pretend some complex calculation happens
    time.sleep(5.0)

    # grab the sum tuple from the tuple space
    print 'main tes1', ts.inp(('sum', object))

    # there shouldn't be any other sum tuple
    try:
        with timeout(2):
            ts.inp(('sum', object))
    except TimeoutError:
        print 'main test2', "no more sums"

    # now lets try something that throws an exception
    ts.eval(breaking_worker)

    # grab the exception tuple from the tuple space
    t = ts.inp((Exception, object))
    print 'main test3', t
Output:
main tes1
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 2,726 Nov-04-2020, 11:26 AM
Last Post: Aggam
  from global space to local space Skaperen 4 2,269 Sep-08-2020, 04:59 PM
Last Post: Skaperen
  How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? SukhmeetSingh 5 3,118 May-21-2019, 11:39 AM
Last Post: avorane
  tuple and formating problem darktitan 7 3,324 Feb-17-2019, 07:37 PM
Last Post: marienbad
  Problem between list and tuple PierreSoulier 2 2,756 Jul-19-2018, 12:40 PM
Last Post: PierreSoulier

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020