Skip to content

Instantly share code, notes, and snippets.

@manchicken
Created August 28, 2013 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manchicken/6369630 to your computer and use it in GitHub Desktop.
Save manchicken/6369630 to your computer and use it in GitHub Desktop.
This is me essentially doing the same thing as in my Perl playing with threads. This is more of me trying to do something in Perl and then replicate it in Python as a means of learning Python.
#!/usr/bin/env python
import sys
import threading
def process_number(func,input_list):
x = 0
n = 0
for one in input_list:
n = n + 1
x = func(x, n, one)
print "Done, result: {answer}".format(answer=x)
def main(argv):
numlist = [5,6,4,5,2,5,6,7,4,5]
print 'Doin\' it!'
avgthread = threading.Thread(target=process_number, args=(lambda p,n,x: float(((p*(n-1))+x)/n), numlist))
sumthread = threading.Thread(target=process_number, args=(lambda p,n,x: (p+x), numlist))
avgthread.start()
sumthread.start()
avgthread.join()
sumthread.join()
print 'Did it!'
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment