psutil icon indicating copy to clipboard operation
psutil copied to clipboard

[Windows] SystemError raised by process.send_signal(signal.CTRL_BREAK_EVENT)

Open JanMatCodasip opened this issue 1 year ago • 0 comments

Summary

  • OS: Microsoft Windows 11 Pro, 10.0.22631 Build 22631
  • Architecture: 64bit
  • Psutil version: 5.9.8 and 7.0.0
  • Python version: 3.12.7
  • Type: core

Description

In psutil 5.9.8, a call to process.send_signal(signal.CTRL_BREAK_EVENT) can raise a SystemError exception whose original cause is a WindowsError (OSError) exception saying [WinError 87] The parameter is incorrect.

In psutil 7.0.0, the OSError is raised directly.

My scenario: I am sending CTRL_BREAK_EVENT to multiple processes. I suspect that the exception is raised because one of the processes manages to exit on its own just before the signal is sent, and the sending of the signal fails with the described error.

Traceback from 7.0.0:

Traceback (most recent call last):
  File "<script_path_censored>.py", line 2019, in <module>
    sys.exit(inst.run())
             ^^^^^^^^^^
  File "<script_path_censored>.py", line 2014, in run
    return testbench.run("tb_ocd_testbench")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<script_path_censored>.py", line 223, in run
    self._run_impl(top)
  File "<script_path_censored>.py", line 689, in _run_impl
    rtlsim_proc.interrupt(sig, force_kill_after=self.HUNG_PROCESS_WAIT_TIME)
  File "<script_path_censored>.py", line 1332, in interrupt
    self._interrupt_whole_subtree_using_psutil(
  File "<script_path_censored>.py", line 1195, in _interrupt_whole_subtree_using_psutil
    p.send_signal(signal_type)
  File "C:\venv\Lib\site-packages\psutil\__init__.py", line 1283, in send_signal
    self._proc.send_signal(sig)
  File "C:\venv\Lib\site-packages\psutil\_pswindows.py", line 675, in wrapper
    raise convert_oserror(err, pid=self.pid, name=self._name) from err
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\venv\Lib\site-packages\psutil\_pswindows.py", line 664, in convert_oserror
    raise exc
  File "C:\venv\Lib\site-packages\psutil\_pswindows.py", line 673, in wrapper
    return fun(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\venv\Lib\site-packages\psutil\_pswindows.py", line 858, in send_signal
    os.kill(self.pid, sig)
OSError: [WinError 87] The parameter is incorrect

In another words, it appears that a situation exists in which os.kill() call can end with WinError 87, however this case does not seem to be accounted for in convert_oserror().

JanMatCodasip avatar Mar 11 '25 14:03 JanMatCodasip