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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:22:52+00:00 2026-06-18T11:22:52+00:00

I have two programs program1.py is like commandline interface which takes command from user

  • 0

I have two programs
program1.py is like commandline interface which takes command from user
program2.py has the program which runs the relevant program as per the command.

Program 1 has also has an quit_program() module
In our simple universe.. lets say I have just one command and just one program
So lets say…

program1.py

def main():
   while True:
        try:

            command = raw_input('> ')
            if command == "quit" :
                return

            if command == '':
                continue
        except KeyboardInterrupt:
            exit()

        parseCommand(command)

And then I have:

 if commmand == "hi":
       say_hi()

Now program2 has

   def say_hi():
      #do something..

Now there can be two cases…
Either say_hi() completes in which case no issue…
But what i want is that if user enters a command (say: end)
then this say_hi() is terminated in between..

But my current implementation is very sequential.. I mean I dont get to type anything on my terminal untill the execution is completed..
Somethng tells me that the say_hi() should be running on another thread?

I am not able to think straight about this.
Any suggestions?
Thanks

  • 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-18T11:22:53+00:00Added an answer on June 18, 2026 at 11:22 am

    The threading module is what you are looking for.

    import threading
    t = threading.Thread(target=target_function,name=name,args=(args))
    t.daemon = True
    t.start()
    

    The .daemon option makes it so you don’t have to explicitly kill threads when your app exits… Threads can be quite nasty otherwise

    Specific to this question and the question in the comments, the say_hi function can be called in another thread as such:

    import threading
    if commmand == "hi":
       t = threading.Thread(target=say_hi, name='Saying hi') #< Note that I did not actually call the function, but instead sent it as a parameter
       t.daemon = True
       t.start() #< This actually starts the thread execution in the background
    

    As a side note, you must make sure you are using thread safe functions inside of threads. In the example of saying hi, you would want to use the logging module instead of print()

    import logging
    logging.info('I am saying hi in a thread-safe manner')
    

    You can read more in the Python Docs.

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

Sidebar

Related Questions

I have a Windows program that has a GUI which also uses a command
I have a command-line executable from which I would like to be able load
I have a program that I run from the command line that looks like
I have a program that generates/'rolls' two dice. I would like to output these
I have two programs: one CLI program, and one GUI. The GUI is a
I have two programs, Writer and Reader. I have a FIFO from Writer to
I've got a table recording views of programs. Each program can have two different
I have two programs: Score.java set to do the following: read scores from the
I would like a batch file to launch two separate programs then have the
here's my issue: I have a program in the command line that has access

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.