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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:22:32+00:00 2026-05-13T01:22:32+00:00

Why do I never get the readyReadStandardOutput signal when I run the following? import

  • 0

Why do I never get the readyReadStandardOutput signal when I run the following?

import os, sys, textwrap

from PyQt4 import QtGui, QtCore

out_file = open("sleep_loop.py", 'w')
out_file.write(textwrap.dedent("""
    import time

    while True:
        print "sleeping..."
        time.sleep(1)"""))
out_file.close()

def started():
    print "started"

def on_error(error):
    errors = ["Failed to start", "Crashed", "Timedout", "Read error", 
              "Write Error", "Unknown Error"]
    print "error: ", errors[error]              

def on_state_change(new_state):
    states = ["Not running", "Starting", "Running"]
    print "new state: ", states[new_state]

def on_out():
    print "got out"

proc = QtCore.QProcess()
sig = QtCore.SIGNAL
proc.connect(proc, sig("started()"), started)
proc.connect(proc, sig("error(ProcessError)"), on_error)
proc.connect(proc, sig("readyReadStandardOutput()"), on_out)
proc.connect(proc, sig("stateChanged(ProcessState)"), 
             on_state_change)
proc.start("python sleep_loop.py")

app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.show()
app.exec_()

proc.close()
  • 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-13T01:22:33+00:00Added an answer on May 13, 2026 at 1:22 am

    Two problems here:

    1. You should create QApplication instance before creating everything else.
    2. Your child process is buffering its output.

    Here is the fixed code, only two lines changed:

    1. app = QApplication moved before proc = QProcess
    2. child process now has sys.stdout.flush()

    And now everything works as you expected:

    import os, sys, textwrap
    
    from PyQt4 import QtGui, QtCore
    
    out_file = open("sleep_loop.py", 'w')
    out_file.write(textwrap.dedent("""
        import time, sys
    
        while True:
            print "sleeping..."
            sys.stdout.flush()
            time.sleep(1)"""))
    out_file.close()
    
    def started():
        print "started"
    
    def on_error(error):
        errors = ["Failed to start", "Crashed", "Timedout", "Read error", 
                  "Write Error", "Unknown Error"]
        print "error: ", errors[error]              
    
    def on_state_change(new_state):
        states = ["Not running", "Starting", "Running"]
        print "new state: ", states[new_state]
    
    def on_out():
        print "got out"
    
    app = QtGui.QApplication(sys.argv)
    proc = QtCore.QProcess()
    sig = QtCore.SIGNAL
    proc.connect(proc, sig("started()"), started)
    proc.connect(proc, sig("error(ProcessError)"), on_error)
    proc.connect(proc, sig("readyReadStandardOutput()"), on_out)
    proc.connect(proc, sig("stateChanged(ProcessState)"), 
                 on_state_change)
    proc.start("python sleep_loop.py")
    
    widget = QtGui.QWidget()
    widget.show()
    app.exec_()
    
    proc.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From what I can gather, there are three categories: Never use GET and use
This is the one thing I could never get to work. My problem is
Google/MyBrain are failing me. Without using a framework (which I'll never get past my
I'm trying to get into java again (it's been a few years). I never
I have never used virtualization, and am trying to get up to speed. My
User equals untrustworthy. Never trust untrustworthy user's input. I get that. However, I am
I've had several clients ask this, and I've never been able to get or
I never actually thought I'd run into speed-issues with python, but I have. I'm
Never used a cache like this before. The problem is that I want to
I've never been completely happy with the way exception handling works, there's a lot

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.