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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:10:27+00:00 2026-05-30T06:10:27+00:00

def function(message): if ‘START’ in message: timer = 10 #start a thread which sleeps

  • 0
def function(message):

  if 'START' in  message:

    timer = 10
    #start a thread which sleeps for 'timer' and prints "TIMER EXPIRED"

  if 'STOP' in message:

    #check if timer is still running, terminate thread if yes (print "TIMER STOPPED")

def main():

  function('START')

  time.sleep(random_time)

  function('STOP')

1.please suggest what kind of thread is best for this program, thread.start_new_thread() doesn’t seem to have exit() or terminate() from main program.

2.how to make sure timer is still running and then terminate thred

need to work with threads since,Process gives an error saying the new process is not able to use variables from old one, i am actually calling other functions rather than printing ‘TIMER EXPIRED’ and ‘TIMER STOPPED’

  • 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-30T06:10:29+00:00Added an answer on May 30, 2026 at 6:10 am

    Here is the code used to stop thread started in previous function call.
    In the first iteration, start thread and pass the reference(i made it global variable)

    global t1, t1_stop

    def timer_run(timer_val):

    time.sleep(timer_val)
    

    def funct():

    global t1, t1_stop
    
    if 'START' in  message:
    
        timer_val =10
    
        t1_stop = threading.Event()
    
        t1 = threading.Thread(target=timer_run, args=(timer_val,))
    
        t1.start()
    
    if 'STOP' in  message:
        t1_stop.set()
    

    def main():

    func('START')
    
    time.sleep(random_time)
    
    func('STOP')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My 'create' function in my 'Message' controller is something like this: def create @message
The following code import gtk import nautilus import os def alert(message): A function to
Given the following function: def foo(a, b, c): pass How would one obtain a
I'm using this simple function: def print_players(players): tot = 1 for p in players:
In python I have the following function: def is_a_nice_element(element, parameter): #do something return True
is there any way I can reproduce this ruby function: def Password.hash(password,salt) Digest::SHA512.hexdigest(#{password}:#{salt}) end
I am writing a script and in my script I have this function: def
My function is def validate_latitude(lat): Enforce latitude is in range >>> validate_latitude(65) 65 >>>
I got a function like def f(): ... ... return [list1, list2] this returns
I wrote a function in Python: def instantiate(c): if inspect.isclass(c): return c() elif isinstance(c,

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.