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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:17:00+00:00 2026-06-12T04:17:00+00:00

My code seems to hang on this popen call command = ls commandList =

  • 0

My code seems to hang on this popen call

command = "ls"
commandList = shlex.split(command)
print("Executing " + command +"\n")
print(commandList)
output = "#" * 10 + "\n" + server.name + "\n\n"
process = subprocess.Popen(
    command,
    shell=True,
    stdin=subprocess.PIPE, 
    stdout=subprocess.PIPE)
output = process.communicate()[0]
#scriptRunner.threadComplete(output)
return output

The code is in the executeScriptOverSSH method on the SshWorker

class WorkerThread(threading.Thread):
    def __init__(self, pathToScript, server, runner):
        super(WorkerThread, self).__init__()
        self.scriptRunner = runner
        self.server = server
        self.pathToScript = pathToScript
        self.sshWorker = SshWorker.SshWorker()

    def run(self):
        print('Thread Starting')
        output = self.sshWorker.executeScriptOverSSH(
            self.server, 
            self.pathToScript)
        print('Thread Finishing!')
        self.scriptRunner.threadComplete(output)`

The threads never get past the call to Popen — I’ve checked by using print statements there. Any ideas?

  • 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-12T04:17:01+00:00Added an answer on June 12, 2026 at 4:17 am

    I’ve run the below code and it runs correctly. You mentioned that “check_output barfs if the return code is non zero”, check out the check_output docs it raises a CalledProcessError exception which you can catch and contains all the error details in a nice structure.

    import threading, subprocess, random, time, pprint
    from subprocess import check_output
    
    class WorkerThread(threading.Thread):
        def __init__(self, user, host, script, runner):
            super(WorkerThread, self).__init__()
            self.user = user
            self.host = host
            self.script = script
            self.runner = runner
    
        def run(self):
            cmd = "ssh {user}@{host} 'bash -s' < {script}".format(**self.__dict__)
            self.runner.complete(check_output(cmd, shell=True))
    
    class Runner(object):
        def complete(self, output):
            print 'output:\n', output
    
    WorkerThread('marwan', 'homebox', 'local_script.sh', Runner()).start()
    

    The code above follows the same structure you posted in your question. But I don’t recommend you take this approach here are some suggestions:

    • From the WorkerThread you call runner, I don’t know the details of runner but when doing multi-threaded programming the most robust thread-safe option is to communicate using a Queue.
    • There are a number of excellent libraries that do what you are doing here hand. They are well tested and do it cleanly. paramiko is excellent and Fabric is really great too.

    simple fabric remote run example

    from fabric.api import run
    
    def anonymous():
        run("uname -a")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code seems to work well, modifying the properties of my button, except the
I am looking to execute a password change over Net-ssh and this code seems
My CI site will sometimes just hang - server seems to take forever to
The code seems not working. // $counter is an instance of Zend_Db_Table_Abstract $counter->update(array('hits' =>
My code seems to do infinite recursion when I invoke it with trees of
My code seems to run but it does not display the result any result
The following javascript code seems to leak memory but I’m not sure why. I’ve
The following code seems to be just too much, for getting a single count
The below code seems like it should work; however, the blob in the database
The following code seems not to work, even though the file appears to be

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.