Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:26:38+00:00 2026-06-17T09:26:38+00:00

Trying to learn multi-threading. I downloaded some sample code to play with, and I

  • 0

Trying to learn multi-threading. I downloaded some sample code to play with, and I ended up with this:

import threading
import time

class myThread (threading.Thread):
    def __init__(self, threadID, name, delay, counter):
        super().__init__()
        self.threadID = threadID
        self.name = name
        self.delay = delay
        self.counter = counter
        threading.Thread.__init__(self)
        print(name,"created")
        print(self.name,"created")
    def run(self):
        print ("Starting " + self.name)
        print_time(self.name, self.delay, self.counter)
        print ("Exiting " + self.name)

def print_time(threadName, delay, counter):
    while counter:
        time.sleep(delay)
        print (threadName, time.ctime(time.time()))
        counter -= 1

# Create new threads
thread1 = myThread(1, "a", 1, 5)
thread2 = myThread(2, "b", 2, 3)

# Start new Threads
thread1.start()
thread2.start()
thread1.join()
thread2.join()

print ("Exiting Main Thread")

But my output was unexpected, to say the least.

a created
Thread-2 created
b created
Thread-4 created
Starting Thread-2
Starting Thread-4
Thread-2 Mon Jan 14 16:14:29 2013
Thread-2 Mon Jan 14 16:14:30 2013
Thread-4 Mon Jan 14 16:14:30 2013
Thread-2 Mon Jan 14 16:14:31 2013
Thread-2 Mon Jan 14 16:14:32 2013
Thread-4 Mon Jan 14 16:14:32 2013
Thread-2 Mon Jan 14 16:14:33 2013
Exiting Thread-2
Thread-4 Mon Jan 14 16:14:34 2013
Exiting Thread-4
Exiting Main Thread

Why doesn’t self.name evaluate to “a” or “b” after assigning it that way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:26:39+00:00Added an answer on June 17, 2026 at 9:26 am

    name gets reinitialized in threading.Thread.__init__(self). There is no reason to call parent constructor twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to learn multithreading and i'm stuck on this sample Imports System.Threading Public
I am trying my hardest to learn Cross/Multi Threading, but I am very confused
I'm trying to come up with some programming puzzles focused on multi-threading. Most of
Trying to learn pointer math better I wrote this code. The intention was to
Trying to learn pointers better I wrote this code. The intention was to print
I was looking at some Cappuccino code (trying learn a little bit of it)
Trying to learn some geospatial python. More or less following the class notes here
I was trying to implement a Matrix.class to learn some Java. Right now, I
Trying to learn a bit about PDO and is going through this tutorial .
Im trying to learn a bit about c++ and have run in to some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.