therefore, It can be realized with the following code : #!/usr/bin/env python import sys try: #pri. So I decided to have a thorough understanding of the environment.
In general ,linux The running script is closed with the closing of the terminal, So how to make the script run in the background and not close with the terminal closing ? What's used here is nohup command Format : nohup Script path & example : nohup. linux The script runs in the background.Stay Linux in, have access to nohup Put the script in the background, as follows : nohup python myscript.py params1 > nohup.out 2>&1 & 1 but. nohup The use of python Version of the problem. Later, I refer to other people's blogs, I finally know the problem. Problems encountered before, Running on a virtual machine python The script runs directly with nohup The results are different, even to the extent that nohup It doesn't work at all. 【Linux Study 】python The script runs directly with nohup The results are different.Two random scripts, When I can run, I'll be happy. Recently got a server, Hang a script to brush riverside online time. function python Script background execution.Ps -ef | grep Productor.py | grep -v grep # Test it first python3 /usr/local/software/ELK/Productor.py # That's all right. see python Script run pid, Give Way python The script runs in the background.python Script background run more related articles
windows Running in the background stay windows I haven't studied it in depth, The way I often use is to modify python The script extension is ".pyw", Double click to run in the background, You don't need to change any code. Now you can see python The program is still running.
At the terminal tmux You can startĮxecute the following command directly ( The script refers to the above ): python test123.pyģ、 Direct closure ssh terminal ( such as putty The close button on ) Ĥ、 again ssh After going up, Execute the following command : tmux attach If you run the program temporarily, Can pass screen、tmux Start the program, Here's a description of tmux Mode of activation. If you use it directly & Start the process : python test123.py &ĭirect closure ssh The terminal causes the process to exit. ġ、 To write python Script t27]# cat test123.pyĢ、 To write upstat The configuration file t27]# cat /etc/init/nfģ、 Reload upstate initctl reload-configurationĤ、 Start the service t27]# start mikeTest Os.dup2(se.fileno(), ())Ĭan pass upstart Encapsulating applications as system services, Here's a complete example. Print 'fork #2 failed: %d (%s)' % (error.errno, error.strerror)
Print 'fork #1 failed: %d (%s)' % (error.errno, error.strerror) How do I not make it block the rest of the Python script and then kill it once the python methods have finished running and returned a value? Much thanks.# This is an example of a specific business function I can't get the get_user_recommendations to run because the JVM server is blocking the process. Where: from py4j.java_gateway import JavaGateway J_id_list = ListConverter().convert(class_list, self.gateway._gateway_client) Print "recommendations" + str(r.get_users_recommendation(sys.argv))ĭef get_users_recommendation(self, user_list):
Python code: process = subprocess.Popen('runJVM.sh', shell=True, stderr=subprocess.STDOUT)Īssert len(sys.argv) > 1, '%d arguments supplied, one needed' %(len(sys.argv)-1) I need the JVM to run while I'm calling another function, and I need to stop the JVM after the process has finished running. However, my problem is that the correct way I have it written, the JVM starts and blocks the rest of the processes that happen after it.
I'm writing an application in python that initiates a JVM in java by calling a shell script using a python subprocess.