1

Now this question might seem like an questions like this one and this one.

However unfortunately the above solutions don't work for me. I need a way to execute a Python 3.4.3 script, leave it running when the terminal closes, and have it not hang in terminal and executed directly.

pi@raspberrypi:/var/www/html/mysite/scripts $ nohup python3 my.script.py &                                                                                                                                                          

The above runs the script, but it hangs in terminal, I cannot enter any other commands until I stop it, by pressing CTRL + C.

Is there a way to achieve something like this:

pi@raspberrypi:/var/www/html/mysite/scripts $ nohup python3 my.script.py &
pi@raspberrypi:/var/www/html/mysite/scripts $ 
(Now I enter more commands, despite the script still running)

I hope I have provided enough information, hopefully you can help me, thanks!

5
  • Looks like you're just missing the ampersand. nohup python3 my.script.py& Commented Nov 10, 2016 at 9:14
  • 1
    With the ampersand, the script should run in the background. I'm not sure what more to tell you. Maybe copy/paste the exact command you executed? And tell us how you've determined that it's "hanging" the terminal? Commented Nov 10, 2016 at 9:26
  • www-data@raspberrypi:~/html/mysite/scripts $ nohup python3 my.script.py & Commented Nov 10, 2016 at 9:30
  • Your script is really called my.script.py? I asked for an exact copy/paste because your initial post had the same line and was missing the ampersand, which would cause the issue you saw. "Extraordinary claims require extraordinary evidence." You're claiming that the ampersand doesn't cause the command to be executed in the background, so you're going to have to be very convincing with your evidence. Commented Nov 10, 2016 at 9:37
  • In this case, it actually is called that. Commented Nov 10, 2016 at 9:40

2 Answers 2

1

Based on a quick google search, I found

start /b python3 my.script.py

for windows or

python3 my.script.py &

on lunix (bash).

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

1 Comment

I ended up fixing it with python3 myscript.py 1 > /dev/null
0

If the ampersand doesn't work, you can use a terminal multiplexer like GNU screen or tmux for your purpose.

1 Comment

I ended up fixing it with python3 myscript.py 1 > /dev/null

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.