4

I'm trying to make a debug console window appear (Needs to share data with the script), still having the main console open. The only way I know how to do it is to execute a second script, and share data with a file..

I would like for the second window to be an actual console.

I'm on Windows 7, and my script doesn't need to be very compatible.

3
  • you mean: compatible = cross-platform? Commented May 25, 2013 at 20:41
  • Doesn't need to be compatible - Should run on my PC, but I don't care about other platforms, So compatible = cross-platform Commented May 25, 2013 at 20:45
  • 1
    You probably want to connect to the process via some remote debugging tool. See stackoverflow.com/questions/543196/… Commented May 25, 2013 at 21:20

2 Answers 2

1

If you are on windows you can use win32console module to open a second console for your child thread(since you want them to share same data) output. This is the most simple and easiest way that works if you are on windows.

Here is a sample code:

import win32console
import threading
from time import sleep

def child_thread():
    win32console.FreeConsole() #Frees child_thread from using main console
    win32console.AllocConsole() #Creates new console and all input and output of the child_thread goes to this new console
   
    while True:
        print("This is in child_thread console and the count is:",count)
        #prints in new console dedicated to this thread

if __name__ == "__main__": 
    count = 0
    threading.Thread(target=child_thread, args=[]).start()
    while True:
        count+=1
        print("Hello from the main console - this is count:", count)
        #prints in main console
        sleep(1)
        #and whatever else you want to do in ur main process

There is also a better method of using queues from the queue module as it gives you a more control over race conditions.

Here is the win32console module documentation

Sign up to request clarification or add additional context in comments.

Comments

0

You could consider going GUI on your application and popping to windows which will have input and output(textboxes) designed as console. Technically both windows will run as one application thus having access to the same namespaces. For wrapping python in GUI check out python Wx and Python TkInter. Best of luck.

PS And it will be pretty compatible :)

1 Comment

Thanks, gonna check that out :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.