Sinisterly
multithreading in python - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Python (https://sinister.li/Forum-Python)
+--- Thread: multithreading in python (/Thread-multithreading-in-python)

Pages: 1 2


multithreading in python - hackejima - 09-28-2014

i have learn to use multithreading in c/c++ but i couldn't get through using it in python or how to use it. Can someone help me on that please or recommend a tutorial or white paper on threading in python . All i have notice on it from several codes is using an instance of the thread module as argument to a class as in "class run(thread.Threading):". Am using python 2.7 win32, any help is appreciated.


multithreading in python - hackejima - 09-28-2014

i have learn to use multithreading in c/c++ but i couldn't get through using it in python or how to use it. Can someone help me on that please or recommend a tutorial or white paper on threading in python . All i have notice on it from several codes is using an instance of the thread module as argument to a class as in "class run(thread.Threading):". Am using python 2.7 win32, any help is appreciated.


RE: multithreading in python - L0aD1nG - 09-28-2014

Hello sir, your question meets my interests. I would like to try help you. This is a sample run of a very basic example of multithreading script I just wrote now to show you.


Spoiler: <span style="font-weight: bold;" class="mycode_b">Code</span>
Code:
## Importing from threading import Thread ## Setting a list to gather the threads for joining thread_list = [] ## Function to use with each thread def func(x, y): print "{} + {} = {}".format(x, y, x+y) ## General loop for item in ((1, 2), (3, 4), (5, 6), (7, 8), (9, 10)): ## Thread Proper Implementation thread = Thread(target=func, args=((item[0], item[1], ))) ## Making each thread daemonic so they will be able to run ## on the background without affecting surely the main program ## execution thread.daemon = True ## Start the each thread thread.start() ## Put it to the list thread_list.append(thread) ## Wait till all the threads are done for thread in thread_list: thread.join()



Spoiler: <span style="font-weight: bold;" class="mycode_b">Image</span>
[Image: 1jtUTWr.png]




I hope this helped out a little, if anything more you want to know or generally anything you would like to ask me please feel free doing it!
Kind Regards.


RE: multithreading in python - L0aD1nG - 09-28-2014

Hello sir, your question meets my interests. I would like to try help you. This is a sample run of a very basic example of multithreading script I just wrote now to show you.


Spoiler: <span style="font-weight: bold;" class="mycode_b">Code</span>
Code:
## Importing from threading import Thread ## Setting a list to gather the threads for joining thread_list = [] ## Function to use with each thread def func(x, y): print "{} + {} = {}".format(x, y, x+y) ## General loop for item in ((1, 2), (3, 4), (5, 6), (7, 8), (9, 10)): ## Thread Proper Implementation thread = Thread(target=func, args=((item[0], item[1], ))) ## Making each thread daemonic so they will be able to run ## on the background without affecting surely the main program ## execution thread.daemon = True ## Start the each thread thread.start() ## Put it to the list thread_list.append(thread) ## Wait till all the threads are done for thread in thread_list: thread.join()



Spoiler: <span style="font-weight: bold;" class="mycode_b">Image</span>
[Image: 1jtUTWr.png]




I hope this helped out a little, if anything more you want to know or generally anything you would like to ask me please feel free doing it!
Kind Regards.


RE: multithreading in python - Psycho_Coder - 09-29-2014

http://www.tutorialspoint.com/python/python_multithreading.htm
http://pymotw.com/2/threading/
http://inventwithpython.com/blog/2013/04/22/multithreaded-python-tutorial-with-threadworms/
http://www.troyfawkes.com/learn-python-multithreading-queues-basics/


RE: multithreading in python - Psycho_Coder - 09-29-2014

http://www.tutorialspoint.com/python/python_multithreading.htm
http://pymotw.com/2/threading/
http://inventwithpython.com/blog/2013/04/22/multithreaded-python-tutorial-with-threadworms/
http://www.troyfawkes.com/learn-python-multithreading-queues-basics/


RE: multithreading in python - hackejima - 09-29-2014

Thanks very much pyscho_coder and LoaD1nG. the code was very helpful especially the links, it was guiding. Thanks for the help.


RE: multithreading in python - hackejima - 09-29-2014

Thanks very much pyscho_coder and LoaD1nG. the code was very helpful especially the links, it was guiding. Thanks for the help.


RE: multithreading in python - L0aD1nG - 09-29-2014

(09-29-2014, 07:22 AM)hackejima Wrote: Thanks very much pyscho_coder and LoaD1nG. the code was very helpful especially the links, it was guiding. Thanks for the help.

You are very welcome, also make sure you put the '@' simbol before you mention a member's name so we get a notification that you mentioned us and we respond as fast as possible.

Like this @hackejima .
Cheers!

NOTE: the 'o' in my name is a zero just to let you know for further mentioning in any case.


RE: multithreading in python - L0aD1nG - 09-29-2014

(09-29-2014, 07:22 AM)hackejima Wrote: Thanks very much pyscho_coder and LoaD1nG. the code was very helpful especially the links, it was guiding. Thanks for the help.

You are very welcome, also make sure you put the '@' simbol before you mention a member's name so we get a notification that you mentioned us and we respond as fast as possible.

Like this @hackejima .
Cheers!

NOTE: the 'o' in my name is a zero just to let you know for further mentioning in any case.