Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working multiple consoles in python

Tags:

python

I know that it is an easy question but I can't do this. I have to do two things. One of them is a management program that will manage the program, e.g stop, pause, resume. The other thing will only show logs. So I need 2 consoles.

  1. How can I open two consoles?

  2. How to pass a log from management console to logging console. Example code is below:


if __name__ == '__main__':
    try:
        while True:
            initialmyProgram()
            print('Please press \'1\' key to stop program..\n')
            print('Please press \'5\' key to resume program..\n')
            print('Please press \'0\' key to exit program..\n')
            isStart = raw_input('Please press a key that must be in above list..')
            if isStart == 1:
                parse.__is__process__ = False
            elif isStart == 5:
                parse.__is__process__ = True
            elif isStart == 0 :
                exit_program()
            else:
                continue
    except Exception as ex:
        logging.info('log..') #this log will write other console..
like image 801
hinzir Avatar asked Oct 22 '22 06:10

hinzir


1 Answers

You don't really need two python consoles to accomplish this.

If you're using linux or a mac, open up a python console and a second terminal.

Then type this command in the second terminal:

tail -f path_to/filename_of_logfile

This will refresh the log file automatically.

An alternative solution if you absolutely cannot use files, is to use sockets to have to python programs communicate. Here's a link to get you started:

Python Sockets

like image 135
Captain Skyhawk Avatar answered Oct 24 '22 05:10

Captain Skyhawk