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

  • Home
  • SEARCH
  • 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 7873293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:28:09+00:00 2026-06-03T02:28:09+00:00

I have following code which compares user input import thread,sys if(username.get_text() == ‘xyz’ and

  • 0

I have following code which compares user input

import thread,sys
if(username.get_text() == 'xyz' and password.get_text()== '123' ):
   thread.start_new_thread(run,()) 

def run():
  print "running client"
  start = datetime.now().second
  while True:
    try:
        host ='localhost'
        port = 5010
        time = abs(datetime.now().second-start)
        time = str(time)
        print time
        client = socket.socket()
        client.connect((host,port))
        client.send(time)
    except socket.error:
        pass

If I just call the function run() it works but when I try to create a thread to run this function, for some reason the thread is not created and run() function is not executed I am unable to find any error..

Thanks in advance…

  • 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-03T02:28:11+00:00Added an answer on June 3, 2026 at 2:28 am

    you really should use the threading module instead of thread.

    what else are you doing? if you create a thread like this, then the interpreter will exit no matter if the thread is still running or not

    for example:

    import thread
    import time
    
    def run():
        time.sleep(2)
        print('ok')
    
    thread.start_new_thread(run, ())
    

    –> this produces:

    Unhandled exception in thread started by 
    sys.excepthook is missing
    lost sys.stderr
    

    where as:

    import threading
    import time
    
    def run():
        time.sleep(2)
        print('ok')
    
    t=threading.Thread(target=run)
    t.daemon = True  # set thread to daemon ('ok' won't be printed in this case)
    t.start()
    

    works as expected. if you don’t want to keep the interpreter waiting for the thread, just set daemon=True* on the generated Thread.

    *edit: added that in example

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

Sidebar

Related Questions

I have following code which works for radio buttons but need to be changed
I want to know is below code correct ? I have following code which
I'm trying to use opengl in C#. I have following code which fails with
I have following Code Block Which I tried to optimize in the Optimized section
I have the following code which throws an exception COM Exception was unhandled in
I have the following code which inserts multiple records into MySQL: foreach ($_POST AS
I have the following code which sometimes return as true and sometimes doesn't. Any
I have the following code which works just fine when the method is POST,
I have the following code which should put programs startable in Bash. if [
I have the following code which reads in the follow file, append a \r\n

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.