views:

143

answers:

3

Pylint is doing something odd on my Windows box - something that shouldn't be possible. This isn't a question about fixing pylint, so much as fixing my understanding.

I have a typical install of the latest version of pylint, Python 2.6 and Windows Vista.

If I open a Command Prompt, and run pylint from the command line, it executes successfully, then when it gets to the end of the program, it doesn't merely exit to the command line again, but closes the entire Command Prompt window.

I had a brief look at the code online (which I assume is the code that is actually being run) and they are calling sys.exit() with various error levels, but my reading and testing suggests that should still just return to the command line with the appropriate error-level set.

Pylint is also run as part of my project's testing regime, and it works there, suggesting to me that if it is called as a Python method rather from the command-line, it doesn't have the same problem (probably no call to sys.exit() in this code path.)

By what mechanism could pylint close the "shell" that contained it?

If this a bug in Pylint? I don't see how. A bug in Python? A bug in Windows?

+1  A: 

I just tried this on XP:

t.bat:

exit

Running this closes the window!

Maybe the command line for pylint uses a batch file which contains an exit?

wallyk
Yes, @wallyk, the Python scripts directory contains pylint.bat which indeed does contain an exit.My mental model of Python and Windows is restored. I thank you.
Oddthinking
+1  A: 

This is a very easy fix. Go into your python scripts folder and locate pylint.bat and open it in notepad.

It will read the following

@echo off
rem = """-*-Python-*- script
rem -------------------- DOS section --------------------
rem You could set PYTHONPATH or TK environment variables here
python -x "%~f0" %*
goto exit

"""
# -------------------- Python section --------------------
import sys
from pylint import lint
lint.Run(sys.argv[1:])


DosExitLabel = """
:exit
exit(ERRORLEVEL)
rem """

To fix the issue at hand of the prompt closing change it to the following

@echo off
rem = """-*-Python-*- script
rem -------------------- DOS section --------------------
rem You could set PYTHONPATH or TK environment variables here
python -x "%~f0" %*
goto exit

"""
# -------------------- Python section --------------------
import sys
from pylint import lint
lint.Run(sys.argv[1:])


DosExitLabel = """
:exit
ECHO.
rem exit(ERRORLEVEL)
rem """

Basically all I did was comment out the exit(ERRORLEVEL) with "rem" keyword then before it goes back to the prompt I added in a blank line print with "ECHO." so that the prompt does not get skewed in with the output.

blewisjr
+1  A: 

This is http://www.logilab.org/ticket/19498 scheduled for 0.20.0 (currently under development).

gurney alex