[BangPypers] Python script hangs after using logging module

Rahul Gopan rahulpcet19 at gmail.com
Tue May 27 06:13:29 CEST 2014


#!/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 <rahulpcet19 at gmail.com> wrote:

>   ------------------------------
> From: Rahul G <rahul at visolve.com>
> Sent: ‎26-‎05-‎2014 05:41 PM
> To: rahulpcet19 at 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 + '; } 2>&1', 'r')
> commands.py(60): text = pipe.read()
>
> Regards,
> Rahul
>
>
>


More information about the BangPypers mailing list