#🔒 Program Not responding [subprocess power shell]

14 messages · Page 1 of 1 (latest)

visual seal
#

Hey guys, I'm having a tiny, mostly cosmetic problem here, would appreciate any help!

First up: I am trying to run a gpupdate on a remote computer with powershell through subprocess.

What happens is when my program gets to the point where it executes the gpupdate function, it goes not responding for a minute or two before returning the expected output.

I assume this is because gpupdate usually takes a bit to run, but is there a way to just tell python to chill until the gpupdate is finished? Or maybe a more efficient way to run the command?

Code block on question:


gpupdate_output = subprocess.run(["powershell", "-Command", rf'cd "C:\Windows\System32\WindowsPowerShell\v1.0\PSTools"; .\Psexec -accepteula \\{pcname} -s -h powershell -command gpupdate /force'],                                     
 shell=True, text=True, capture_output=True)    
 if "Computer Policy update has completed successfully" in gpupdate_output.stdout: 
        gpupdate_status = True     
else:     
    gpupdate_status = False     return gpupdate_status```
wild tapirBOT
#

@visual seal

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

marsh pilot
visual seal
#

Would that allow for user input while function is running? I basically want the user to just hang out while it runs, instead of closing the program if it hits not responding

marsh pilot
visual seal
marsh pilot
#

!e

import threading
import time

def foo(*args):
    print(f"foo({args})")
    time.sleep(3)
    print("Hello")


thread: threading.Thread = threading.Thread(target=foo, args=(1, 2, 3, 4))
thread.start()
print("Main thread")
time.sleep(1)
print("Main thread 2")
wild tapirBOT
marsh pilot
#

As you can see however, the multithreading can cause problems with the print. In this case, the print in foo managed to print it's f-string, then the print in the main thread managed to send it's string, then both (idk in which order), send their end string, which is - by default - the '\n'.

#

If we re-run the same code, we might see a different output

visual seal
#

Okay, I'll save that and try to wrap my head around it lol

wild tapirBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.