[BangPypers] Fwd: Python script hangs after using logging module

Rahul Gopan rahulpcet19 at gmail.com
Tue May 27 08:58:25 CEST 2014


---------- Forwarded message ----------
From: Rahul Gopan <rahulpcet19 at 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 <noufal at 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
<noufal at nibrahim.net.in>wrote:

> 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
>


More information about the BangPypers mailing list