Created
August 28, 2013 18:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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