O'Reilly logo

Python Parallel Programming Cookbook by Giancarlo Zaccone

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to define a thread

The simplest way to use a thread is to instantiate it with a target function and then call the start() method to let it begin its work. The Python module threading has the Thread() method that is used to run processes and functions in a different thread:

class threading.Thread(group=None,
                       target=None,
                       name=None,
                       args=(),
                       kwargs={}) 

In the preceding code:

  • group: This is the value of group that should be None; this is reserved for future implementations
  • target: This is the function that is to be executed when you start a thread activity
  • name: This is the name of the thread; by default, a unique name of the form Thread-N is assigned to it
  • args: This is the tuple of arguments that are to be passed to a target
  • kwargs: This is the dictionary ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required