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 7503453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:13:40+00:00 2026-05-29T21:13:40+00:00

well,I wrote a little snappet trying to know how to use python threading .

  • 0

well,I wrote a little snappet trying to know how to use python threading .
But strangely the following code just quit quickly without the expected output.
Is it because I shouldn’t spawn threads by overiding the run() method?

import threading
from time import sleep
class mythread(threading.Thread):
    def __init__(self,target=None,thread_num=5):
        threading.Thread.__init__(self,target=None)
        self.thn = thread_num

    def run(self):
        for i in range(self.thn):
            t = threading.Thread(target=self.myfunc)
            t.start()
            t.join()
        myfunc(self.thn)

    def myfunc(num):
        print num,'\tI am doing sth.'
        sleep(0.5)
        print num,'\tI have done it.'

mythread()
  • 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-05-29T21:13:42+00:00Added an answer on May 29, 2026 at 9:13 pm

    You need to start the thread to make it actually do something:

    t = mythread()
    t.start()
    

    If you bother to accept a target parameter in your constructor (why?), you shouldn’t ignore this parameter. Maybe you want to pass it on to the Thread constructor. (Why?)

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

Sidebar

Related Questions

I just wrote some code that works very well. But I feel that it
Well, I know a little HTML, and I'm just interested in playing around with
Well, the caption of the question might be a little off, but I didn't
I wrote a little Python script wrapcl.py script which wraps our compiler binary (
Well i wrote a c++ app for a Windows CE device and selected the
Well I have this MySQL stored procedure that I wrote and if I run
I once wrote a Tetris AI that played Tetris quite well. The algorithm I
Well I'm a bit of an idiot, I wrote a view then accidently closed
This snippet works well if I try to write in a user directory but
I'm using Jython to write tests for a Java project. It works well, but

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.