FAQ
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>

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedJan 16, '11 at 3:34p
activeJan 16, '11 at 3:34p
posts1
users1
websitepython.org

1 user in discussion

Moses: 1 post

People

Translate

site design / logo © 2022 Grokbase