Thread vs streaming

What is the difference between threading and thread modules in Python?

+56
python multithreading python-multithreading
Apr 6 2018-11-11T00:
source share
4 answers

In Python 3, thread was renamed to _thread . This is the infrastructure code that is used to implement threading , and normal Python code should not come close to it.

_thread provides a pretty rough idea of ​​the underlying OS-level processes. This is almost never what you want, so rename it to Py3k to indicate that it is really just an implementation detail.

threading adds some additional automatic accounting, as well as several handy utilities, all of which make it the preferred option for standard Python code.

+73
Apr 7 '11 at 8:30
source share

threading is just a higher level module that interacts with thread .

See here for threading docs:

http://docs.python.org/library/threading.html

+27
Apr 6 2018-11-11T00:
source share

If I'm not mistaken, thread allows you to run the function as a separate thread, while threading you should create a class, but get more functionality.

EDIT: This is not true. The threading module provides various ways to create a thread:

  • threading.Thread(target=function_name).start()
  • Create a threading.Thread child class using the run() native method and run it
+11
Apr 6 2018-11-11T00:
source share

The Thread module considers the thread as a function, and the Threading module is implemented in an object-oriented manner, that is, each thread corresponds to an object.

-2
Jun 07 '15 at 3:38
source share



All Articles