---
title: How to run a multi-thread in Python
description: How to run a multi-thread in Python
---

[Skip to content](https://www.connysoderholm.com/blog/multithread-python#main-content)

![Conny-Söderholm](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg)

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

Open main navigation

Close main navigation

- [Home](https://www.connysoderholm.com/)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)

 July 14, 2018

# How to run a multi-thread in Python

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm)

Share: [facebook-f icon](http://www.facebook.com/share.php?u=https://www.connysoderholm.com/blog/multithread-python) [linkedin-in icon](http://www.linkedin.com/shareArticle?mini=true&url=https://www.connysoderholm.com/blog/multithread-python) [Twitter icon](https://twitter.com/intent/tweet?url=https://www.connysoderholm.com/blog/multithread-python) [pinterest-p icon](http://pinterest.com/pin/create/link/?url=https://www.connysoderholm.com/blog/multithread-python) [envelope icon](mailto:?body=https://www.connysoderholm.com/blog/multithread-python)

# Introduction

*How to run a multi-thread in Python* - While coding, we sometimes want the program to do multiple things at once. You may have a script where you run a background function, checking for changes as you go along. It can also be as simple as disabling an Entry to not allow the user to input more text for a while. In this post, we will look at a simple way of how to use multiple threads in Python.

Let us start with a thread running in the background. First, we define our background function background\_thread. We give it the loops argument to know how many times it should execute. We then use the time.sleep method to wait for two seconds before continuing the loop. We start the thread and then enter our target as the background\_thread function, with the arguments 5. Note that you have to put your argument enclosed in parentheses and with a comma after it. In case that you omit the comma, you will get the following error message: TypeError: background\_thread() argument after \* must be an iterable, not int.

Start the thread with the start method. Note that we are using a boolean thread\_finished to check whether the background thread is done. We do this check with the isAlive method of the threading class.  Your output should be like below when you run the code.

*Background thread, doing loop number: 1*  
*Write something here:*  
*ok*  
*You wrote: ok*  
*Write something here:*  
*Background thread, doing loop number: 2*  
*ok2*  
*You wrote: ok2*  
*Write something here:*  
*Background thread, doing loop number: 3*  
*Background thread, doing loop number: 4*  
*ok3*  
*You wrote: ok3*  
*Write something here:*  
*Background thread, doing loop number: 5*  
*Exiting background\_thread*  
*I am done*  
*You wrote: I am done*

```
#! python3

import threading

import time

def background_thread(loops):
for i in range(loops):
print("Background thread, doing loop number: {}".format(i+1))
time.sleep(2)
print("Exiting background_thread")

background_thread = threading.Thread(target=background_thread, args=(5,) )
background_thread.start()
thread_finished = False

while not thread_finished:
if not background_thread.isAlive():
thread_finished = True
else:
my_input = input("Write something here:\n")
print("You wrote: {}".format(my_input))
```

 

[Python](https://www.connysoderholm.com/blog/tag/python)

## Related posts

[Python](https://www.connysoderholm.com/blog/tag/python)

## [Printing dates in Python with the datetime module](https://www.connysoderholm.com/blog/python-datetime-module)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 June 20, 2018

Printing dates in Python with the datetime module - Today we are going to dive into the datetime...

[Read more](https://www.connysoderholm.com/blog/python-datetime-module)

[Python](https://www.connysoderholm.com/blog/tag/python)

## [How to search for files on your computer faster with Python](https://www.connysoderholm.com/blog/search-files-on-your-computer-faster-with-python)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 June 28, 2018

How to search for files on your computer faster with Python When I use the Windows Explorer search...

[Read more](https://www.connysoderholm.com/blog/search-files-on-your-computer-faster-with-python)

[Python](https://www.connysoderholm.com/blog/tag/python)

## [Creating a button in Tkinter](https://www.connysoderholm.com/blog/creating-a-button-in-tkinter)

![Picture of Conny Söderholm](https://app.hubspot.com/settings/avatar/c60eb763b898c1f4c2e54f9401f3aef1) [Conny Söderholm](https://www.connysoderholm.com/blog/author/conny-soderholm) 

 July 9, 2018

Creating a button in Tkinter In this article, we will explore how to create a simple button in...

[Read more](https://www.connysoderholm.com/blog/creating-a-button-in-tkinter)

[linkedin-in icon](https://www.linkedin.com/in/connysoderholm) [Follow us on Facebook](https://www.youtube.com/@connysoderholm1473)

- [Home](https://www.connysoderholm.com)
- [Courses](https://www.connysoderholm.com/courses)
- [Articles](https://www.connysoderholm.com/blog)
- [Contact Me](https://www.connysoderholm.com/contact-me)
- [Privacy Policy](https://www.connysoderholm.com/privacy-policy)
- [Disclaimer](https://www.connysoderholm.com/disclaimer)

---

[![Conny Söderholm Logo](https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg "Conny Söderholm Logo")](http://Conny%20Söderholm)

Copyright © 2026 Conny Söderholm

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Conny Söderholm",
    "url" : "https://www.connysoderholm.com/blog/author/conny-soderholm"
  },
  "dateModified" : "2023-07-31T15:04:17.112Z",
  "datePublished" : "2018-07-14T11:16:55.000Z",
  "headline" : "How to run a multi-thread in Python",
  "mainEntityOfPage" : {
    "@id" : "https://www.connysoderholm.com/blog/multithread-python",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://www.connysoderholm.com/hubfs/Conny-S%C3%B6derholm.svg"
    },
    "name" : "Conny Söderholm"
  }
}
```