Reported by Sini Mäkelä, using 0.38.0 on Windows, python 2.5.2:
Traceback (most recent call last):
File "c:\Python25\Scripts\pylint.bat", line 11, in <module>
from pylint import lint
File "C:\Python25\Lib\site-packages\pylint\lint.py", line 31, in <module>
from pylint.checkers import utils
File "C:\Python25\Lib\site-packages\pylint\checkers\__init__.py", line 40, in <module>
from logilab.astng.utils import ASTWalker
File "C:\Python25\Lib\site-packages\logilab\astng\__init__.py", line 256, in <module>
List._proxied = MANAGER.astng_from_class(list)
File "C:\Python25\Lib\site-packages\logilab\astng\manager.py", line 191, in astng_from_class
modastng = self.astng_from_module_name(modname)
File "C:\Python25\Lib\site-packages\logilab\astng\manager.py", line 142, in astng_from_module_name
return self.astng_from_module(module, modname)
File "C:\Python25\Lib\site-packages\logilab\astng\manager.py", line 176, in astng_from_module
from logilab.astng.builder import ASTNGBuilder
File "C:\Python25\Lib\site-packages\logilab\astng\builder.py", line 40, in <module>
from logilab.common.fileutils import norm_read
File "c:\python25\lib\site-packages\logilab\common\fileutils.py", line 25, in <module>
from logilab.common.shellutils import find
File "C:\Python25\Lib\site-packages\logilab\common\shellutils.py", line 23, in <module>
from logilab.common.proc import ProcInfo, NoSuchProcess
File "C:\Python25\Lib\site-packages\logilab\common\proc.py", line 115, in <module>
from signal import signal, SIGXCPU, SIGKILL, SIGUSR2, SIGUSR1
ImportError: cannot import name SIGXCPU
| |
| priority | important |
|---|---|
| type | bug |
| appeared in | <not specified> |
| done in | 0.39.0 |
| load | 0.250 |
| load left | 0.000 |
| closed by | <not specified> |


#7133 new pyro_ext.py module
Comments
-
2009/02/03 12:10 | reply to this comment
-
2009/02/09 23:14, written by anon
| reply to this comment
-
2009/02/18 15:32, written by anon
| reply to this comment
-
2009/02/18 15:58, written by anon
| reply to this comment
-
2009/02/19 00:10, written by anon
| reply to this comment
-
2009/03/03 17:12, written by anon
| reply to this comment
-
2009/02/25 11:04, written by anon
| reply to this comment
-
2009/02/26 11:50, written by anon
| reply to this comment
-
2009/02/26 12:25, written by sthenault
| reply to this comment
(add comment)Changing line 115 of logilab/common/proc.py to:
should be enough to get pylint to run.
The change was probably introduced for apycot which does not run on Windows anyway.
two more lines that need to be changed to get it to run on Windows:
from signal import *
from os import *
from threading import Timer, currentThread, Thread, Event
from time import time
# from resource import getrlimit, setrlimit, RLIMIT_CPU, RLIMIT_AS
Actually, none of this, including the MemorySentinel and ResourceController classes will work except on UNIX. (e.g. the resource module and os.setpgrp() are listed as only available on UNIX). I did the following:
try:
from signal import signal, SIGXCPU, SIGKILL, SIGUSR2, SIGUSR1
from os import killpg, getpid, setpgrp
from resource import getrlimit, setrlimit, RLIMIT_CPU, RLIMIT_AS
except ImportError: #not UNIX
pass
and then
try:
class ResourceError(BaseException):
...
except NameError:
class MemorySentinel(Thread):
def __init__(self, interval, memory_limit, gpid):
raise NotImplementedError, \
"MemorySentinel class only available on UNIX"
then
try:
class ResourceController:
...
except NameError:
class ResourceController:
def __init__(self, max_cpu_time=None, max_time=None, max_memory=None,
max_reprieve=60):
raise NotImpelementedError, \
"ResourceController only available on UNIX"
so as to specifically alert if its not working.
I'm not sure where to put this so, here's a patch of what I did:
--- C:/Program Files/Python24/Lib/site-packages/logilab_common-0.38.0-py2.4.egg/logilab/common/proc.py Wed Feb 18 09:33:46 2009 +++ C:/PROJ/LOADS/proc.py Wed Feb 18 09:49:39 2009 @@ -112,13 +112,15 @@ import tempfile import traceback -from signal import signal, SIGXCPU, SIGKILL, SIGUSR2, SIGUSR1 -from os import killpg, getpid, setpgrp +try: + from signal import signal, SIGXCPU, SIGKILL, SIGUSR2, SIGUSR1 + from os import killpg, getpid, setpgrp + from resource import getrlimit, setrlimit, RLIMIT_CPU, RLIMIT_AS +except ImportError: #not UNIX + pass from threading import Timer, currentThread, Thread, Event from time import time -from resource import getrlimit, setrlimit, RLIMIT_CPU, RLIMIT_AS - try: class ResourceError(BaseException):
"""Error raise when resource limit is reached"""
@@ -145,117 +147,131 @@
# Can't use subclass because the StandardError MemoryError raised
RESOURCE_LIMIT_EXCEPTION = (ResourceError, MemoryError)
-
-class MemorySentinel(Thread):
- """A class checking a process don't use too much memory in a separated
- daemonic thread
- """
- def __init__(self, interval, memory_limit, gpid=getpid()):
- Thread.__init__(self, target=self._run, name="Test.Sentinel")
- self.memory_limit = memory_limit
- self._stop = Event()
- self.interval = interval
- self.setDaemon(True)
- self.gpid = gpid
+try:
+ class MemorySentinel(Thread):
+ """A class checking a process don't use too much memory in a separated
+ daemonic thread
+ """
+ def __init__(self, interval, memory_limit, gpid=getpid()):
+ Thread.__init__(self, target=self._run, name="Test.Sentinel")
+ self.memory_limit = memory_limit
+ self._stop = Event()
+ self.interval = interval
+ self.setDaemon(True)
+ self.gpid = gpid
- def stop(self):
- """stop ap"""
- self._stop.set()
+ def stop(self):
+ """stop ap"""
+ self._stop.set()
- def _run(self):
- pil = ProcInfoLoader()
- while not self._stop.isSet():
- if self.memory_limit <= pil.load(self.gpid).lineage_memory_usage():
- killpg(self.gpid, SIGUSR1)
- self._stop.wait(self.interval)
-
-
-class ResourceController:
-
- def __init__(self, max_cpu_time=None, max_time=None, max_memory=None,
- max_reprieve=60):
- self.max_time = max_time
- self.max_memory = max_memory
- self.max_cpu_time = max_cpu_time
- self._reprieve = max_reprieve
- self._timer = None
- self._msentinel = None
- self._old_max_memory = None
- self._old_usr1_hdlr = None
- self._old_max_cpu_time = None
- self._old_usr2_hdlr = None
- self._old_sigxcpu_hdlr = None
- self._limit_set = 0
- self._abort_try = 0
- self._start_time = None
- self._elapse_time = 0
+ def _run(self):
+ pil = ProcInfoLoader()
+ while not self._stop.isSet():
+ if self.memory_limit <= pil.load(self.gpid).lineage_memory_usage():
+ killpg(self.gpid, SIGUSR1)
+ self._stop.wait(self.interval)
+except NameError:
+ class MemorySentinel(Thread):
+
+ def __init__(self, interval, memory_limit, gpid):
+ raise NotImplementedError, \
+ "MemorySentinel class only available on UNIX"
+
- def _hangle_sig_timeout(self, sig, frame):
- raise TimeoutError()
+try:
+ class ResourceController:
+
+ def __init__(self, max_cpu_time=None, max_time=None, max_memory=None,
+ max_reprieve=60):
+ self.max_time = max_time
+ self.max_memory = max_memory
+ self.max_cpu_time = max_cpu_time
+ self._reprieve = max_reprieve
+ self._timer = None
+ self._msentinel = None
+ self._old_max_memory = None
+ self._old_usr1_hdlr = None
+ self._old_max_cpu_time = None
+ self._old_usr2_hdlr = None
+ self._old_sigxcpu_hdlr = None
+ self._limit_set = 0
+ self._abort_try = 0
+ self._start_time = None
+ self._elapse_time = 0
+
+ def _hangle_sig_timeout(self, sig, frame):
+ raise TimeoutError()
- def _hangle_sig_memory(self, sig, frame):
- if self._abort_try < self._reprieve:
- self._abort_try += 1
- raise LineageMemoryError("Memory limit reached")
- else:
- killpg(getpid(), SIGKILL)
-
- def _handle_sigxcpu(self, sig, frame):
- if self._abort_try < self._reprieve:
- self._abort_try += 1
- raise XCPUError("Soft CPU time limit reached")
- else:
- killpg(getpid(), SIGKILL)
-
- def _time_out(self):
- if self._abort_try < self._reprieve:
- self._abort_try += 1
- killpg(getpid(), SIGUSR2)
+ def _hangle_sig_memory(self, sig, frame):
+ if self._abort_try < self._reprieve:
+ self._abort_try += 1
+ raise LineageMemoryError("Memory limit reached")
+ else:
+ killpg(getpid(), SIGKILL)
+
+ def _handle_sigxcpu(self, sig, frame):
+ if self._abort_try < self._reprieve:
+ self._abort_try += 1
+ raise XCPUError("Soft CPU time limit reached")
+ else:
+ killpg(getpid(), SIGKILL)
+
+ def _time_out(self):
+ if self._abort_try < self._reprieve:
+ self._abort_try += 1
+ killpg(getpid(), SIGUSR2)
+ if self._limit_set > 0:
+ self._timer = Timer(1, self._time_out)
+ self._timer.start()
+ else:
+ killpg(getpid(), SIGKILL)
+
+ def setup_limit(self):
+ """set up the process limit"""
+ assert currentThread().getName() == 'MainThread'
+ setpgrp()
+ if self._limit_set <= 0:
+ if self.max_time is not None:
+ self._old_usr2_hdlr = signal(SIGUSR2, self._hangle_sig_timeout)
+ self._timer = Timer(max(1, int(self.max_time) - self._elapse_time),
+ self._time_out)
+ self._start_time = int(time())
+ self._timer.start()
+ if self.max_cpu_time is not None:
+ self._old_max_cpu_time = getrlimit(RLIMIT_CPU)
+ cpu_limit = (int(self.max_cpu_time), self._old_max_cpu_time[1])
+ self._old_sigxcpu_hdlr = signal(SIGXCPU, self._handle_sigxcpu)
+ setrlimit(RLIMIT_CPU, cpu_limit)
+ if self.max_memory is not None:
+ self._msentinel = MemorySentinel(1, int(self.max_memory) )
+ self._old_max_memory = getrlimit(RLIMIT_AS)
+ self._old_usr1_hdlr = signal(SIGUSR1, self._hangle_sig_memory)
+ as_limit = (int(self.max_memory), self._old_max_memory[1])
+ setrlimit(RLIMIT_AS, as_limit)
+ self._msentinel.start()
+ self._limit_set += 1
+
+ def clean_limit(self):
+ """reinstall the old process limit"""
if self._limit_set > 0:
- self._timer = Timer(1, self._time_out)
- self._timer.start()
- else:
- killpg(getpid(), SIGKILL)
-
- def setup_limit(self):
- """set up the process limit"""
- assert currentThread().getName() == 'MainThread'
- setpgrp()
- if self._limit_set <= 0:
- if self.max_time is not None:
- self._old_usr2_hdlr = signal(SIGUSR2, self._hangle_sig_timeout)
- self._timer = Timer(max(1, int(self.max_time) - self._elapse_time),
- self._time_out)
- self._start_time = int(time())
- self._timer.start()
- if self.max_cpu_time is not None:
- self._old_max_cpu_time = getrlimit(RLIMIT_CPU)
- cpu_limit = (int(self.max_cpu_time), self._old_max_cpu_time[1])
- self._old_sigxcpu_hdlr = signal(SIGXCPU, self._handle_sigxcpu)
- setrlimit(RLIMIT_CPU, cpu_limit)
- if self.max_memory is not None:
- self._msentinel = MemorySentinel(1, int(self.max_memory) )
- self._old_max_memory = getrlimit(RLIMIT_AS)
- self._old_usr1_hdlr = signal(SIGUSR1, self._hangle_sig_memory)
- as_limit = (int(self.max_memory), self._old_max_memory[1])
- setrlimit(RLIMIT_AS, as_limit)
- self._msentinel.start()
- self._limit_set += 1
-
- def clean_limit(self):
- """reinstall the old process limit"""
- if self._limit_set > 0:
- if self.max_time is not None:
- self._timer.cancel()
- self._elapse_time += int(time())-self._start_time
- self._timer = None
- signal(SIGUSR2, self._old_usr2_hdlr)
- if self.max_cpu_time is not None:
- setrlimit(RLIMIT_CPU, self._old_max_cpu_time)
- signal(SIGXCPU, self._old_sigxcpu_hdlr)
- if self.max_memory is not None:
- self._msentinel.stop()
- self._msentinel = None
- setrlimit(RLIMIT_AS, self._old_max_memory)
- signal(SIGUSR1, self._old_usr1_hdlr)
- self._limit_set -= 1
+ if self.max_time is not None:
+ self._timer.cancel()
+ self._elapse_time += int(time())-self._start_time
+ self._timer = None
+ signal(SIGUSR2, self._old_usr2_hdlr)
+ if self.max_cpu_time is not None:
+ setrlimit(RLIMIT_CPU, self._old_max_cpu_time)
+ signal(SIGXCPU, self._old_sigxcpu_hdlr)
+ if self.max_memory is not None:
+ self._msentinel.stop()
+ self._msentinel = None
+ setrlimit(RLIMIT_AS, self._old_max_memory)
+ signal(SIGUSR1, self._old_usr1_hdlr)
+ self._limit_set -= 1
+except NameError:
+ class ResourceController:
+
+ def __init__(self, max_cpu_time=None, max_time=None, max_memory=None,
+ max_reprieve=60):
+ raise NotImpelementedError, \
+ "ResourceController only available on UNIX"
The try/except did the trick, now i can run pylint on windows.
thanks, patch did work for me (Win32)
Thanks a lot, pylint seems to work on windows with these modifications.
issue not fixed in 0.38.1
gasp, that's true 0.38.1 did not include the patch fixing this...