[PYTHON] threading: Parallel processing

Moses jamuah at gmail.com
Sun Jan 16 10:34:15 EST 2011


Hi All,

Is there is a way to print or use the value of new in the main function of
the script below?


from thread import start_new_thread, allocate_lock

num_threads = 0
thread_started = False
lock = allocate_lock()

def heron(a):
    global num_threads, thread_started
    lock.acquire()
    num_threads += 1
    thread_started = True
    lock.release()
    """Calculates the square root of a"""
    eps = 0.0000001
    old = 1
    new = 1
    while True:
        old,new = new, (new + a/new) / 2.0
        print old, new
        if abs(new - old) < eps:
            break
    lock.acquire()
    num_threads -= 1
    lock.release()
    return new

start_new_thread(heron,(81,))
start_new_thread(heron,(999,))
start_new_thread(heron,(1733,))


while not thread_started:
    pass
while num_threads > 0:
    pass

Thanks,

Moses.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110116/9cc785ab/attachment.html>


More information about the Python-list mailing list