[BangPypers] Restart when python script hangs
Hello, When I run a python script it hangs at random places. Is there any way to identify when the script hangs and to resume it automatically. When I see that it is not responding i do ^Z (Ctrl -Z) to stop and then use fg command to start it again. I want to automate this. Kindly help me how it can done Regards, Rahul G ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
[BangPypers] Fwd: Python script hangs after using logging module
-- Forwarded message -- From: Rahul Gopan rahulpce...@gmail.com Date: Tue, May 27, 2014 at 12:06 PM Subject: Re: [BangPypers] Python script hangs after using logging module To: Noufal Ibrahim KV nou...@nibrahim.net.in 1. Used subprocess.check_output. . Same result , it hangs 2. Am trying to run a bin file /bin/range branch Begin_No End_No which is supposed to provide me the number of items available between the Begin_No and End_No. I guess its not waiting for any input, it works like charm outside the python code. 3. Running the command outside works file. It hangs only when i use logging.basicConfig(filename= 'Log_file.log',filemode='w',format='%(asctime)s %(message)s',level=logging.DEBUG) before executing the command /bin/range 4. Without logging line it works fine so i guess there wont be any issue with being same directory or environment. 5. Creating the file manually outside the script works. No issue with that. Help me to resolve this Regards, Rahul On Tue, May 27, 2014 at 10:48 AM, Noufal Ibrahim KV nou...@nibrahim.net.inwrote: On Tue, May 27 2014, Rahul Gopan wrote: #!/usr/local/bin/python2.7 import commands import subprocess items = commands.getoutput('COMMAND branch Begin_no End_no | wc -l') print items -- Works -- #!/usr/local/bin/python2.7 import commands import subprocess import logging logging.basicConfig(filename='Log_file.log',filemode='w',format='%(asctime)s %(message)s',level=logging.DEBUG) items = commands.getoutput('COMMAND branch Begin_no End_no | wc -l') print items -- Hangs -- A few suggestions. 1. Consider using subprocess or envoy[1] instead of commands. It's deprecated. 2. Please specify exactly what you're trying to run rather than the placeholder you've put in your script above. My guess is that it's waiting for input and holding up the pipeline so that wc is never run. 3. Try running that command outside to see what the behaviour is. 4. If the command works, make sure that your script is running in the same directory and with the same environment as the one where the command works. 5. I'd be inclined to do the `wc` in Python rather than use a pipe. It looks okay in this case but usually, involving the shell while trying to execute something leads to headaches with quoting, variable expansion and other such things that are not worth it. 6. The basicConfig line will actually create and open the Log_file.log file. If you're on a disk that's misbehaving (e.g. a stale NFS mount), it might hang. Try creating the file manually outside the script to see if that's the issue. [...] Footnotes: [1] https://github.com/kennethreitz/envoy -- Cordially, Noufal http://nibrahim.net.in ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
[BangPypers] Python script hangs after using logging module
-Original Message- From: Rahul G ra...@visolve.com Sent: 26-05-2014 05:41 PM To: rahulpce...@gmail.com rahulpce...@gmail.com Subject: Python script hangs after using logging module Hello, I tried to make a log file in a python script. After adding the line below logging.basicConfig(filename='LOG_FILE.log', filemode='w', format='%(asctime)s %(message)s', level=logging.DEBUG) Now when I try to run a binary file using os.system or commands.getoutput, script simply hangs. Binary file is supposed to provide me the number of items available within two numbers in a particular branch Usage of that command : range branch Begin_number End_number Without using the above logging line, I could run this command. I used trace python -m trace --trace myscript.sh to see where exactly it hangs.Last few lines from the output of trace work of python is commands.py(58): import os commands.py(59): pipe = os.popen('{ ' + cmd + '; } 21', 'r') commands.py(60): text = pipe.read() Regards, Rahul ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers
Re: [BangPypers] Python script hangs after using logging module
#!/usr/local/bin/python2.7 import commands import subprocess items = commands.getoutput('COMMAND branch Begin_no End_no | wc -l') print items -- Works -- #!/usr/local/bin/python2.7 import commands import subprocess import logging logging.basicConfig(filename='Log_file.log',filemode='w',format='%(asctime)s %(message)s',level=logging.DEBUG) items = commands.getoutput('COMMAND branch Begin_no End_no | wc -l') print items -- Hangs -- Help me to resolve it On Mon, May 26, 2014 at 5:42 PM, Rahul Gopan rahulpce...@gmail.com wrote: -- From: Rahul G ra...@visolve.com Sent: 26-05-2014 05:41 PM To: rahulpce...@gmail.com Subject: Python script hangs after using logging module Hello, I tried to make a log file in a python script. After adding the line below logging.basicConfig(filename='LOG_FILE.log', filemode='w', format='%(asctime)s %(message)s', level=logging.DEBUG) Now when I try to run a binary file using os.system or commands.getoutput, script simply hangs. Binary file is supposed to provide me the number of items available within two numbers in a particular branch Usage of that command : range branch Begin_number End_number Without using the above logging line, I could run this command. I used trace python -m trace --trace myscript.sh to see where exactly it hangs.Last few lines from the output of trace work of python is commands.py(58): import os commands.py(59): pipe = os.popen('{ ' + cmd + '; } 21', 'r') commands.py(60): text = pipe.read() Regards, Rahul ___ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers