New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFE: faulthandler.register() should support file descriptors #67754
Comments
Currently, functions of the faulthandler module require a file-like object (with a fileno() method). It would be nice to accept also file descriptors (int). Example of code using faulthandler which creates an useless file object just to pass a file descriptor: |
Only faulthandler_get_fileno() should be modified, but a new unit test should be added. |
Attached a patch to this issue. Made some changes to faulthandler_get_fileno to accept integer as fd. If a fd is provided, the file member of fatal_error struct is set NULL. An new test case is added and some common testing code is also changed in order to be reused. |
@kilowu: Thanks, I reviewed your patch. |
issue23566_update.patch looks good to me, but I suggested some minor changes. Usually, I do such changes myself, but I proposed this issue on the Python menthorship list, so I prefer to do the changes to learn the process of reviewing patches and taking comments in account ;-) |
Updated the patch and addressed the previous review comments:
Let me know if there is possible further improvement in this patch. : ) |
New changeset e78de5b1e3ef by Victor Stinner in branch 'default': |
I was going to push your change, but I noticed that you use stderr.fileno() in tests. I modified the test to use a different file descriptor. sys.stderr is also the default value, so the test may pass because the file descriptor was ignored (if there was a bug in your change, which is not the case). I pushed the modified patch. Thanks for your contribution Wei Wu! |
Oops, I forgot Windows. On Windows, we should maybe use stderr.fileno() and avoid pass_fds. (Or maybe just skip the tests on Windows?) ====================================================================== Traceback (most recent call last):
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_faulthandler.py", line 378, in test_dump_traceback_fd
self.check_dump_traceback(fd=fp.fileno())
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_faulthandler.py", line 365, in check_dump_traceback
trace, exitcode = self.get_output(code, filename, fd)
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_faulthandler.py", line 60, in get_output
process = script_helper.spawn_python('-c', code, pass_fds=pass_fds)
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\script_helper.py", line 136, in spawn_python
**kw)
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\subprocess.py", line 855, in __init__
restore_signals, start_new_session)
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\subprocess.py", line 1096, in _execute_child
assert not pass_fds, "pass_fds not supported on Windows."
AssertionError: pass_fds not supported on Windows. ====================================================================== Traceback (most recent call last):
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_faulthandler.py", line 235, in test_enable_fd
fd=fd)
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_faulthandler.py", line 106, in check_fatal_error
output, exitcode = self.get_output(code, filename=filename, fd=fd)
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\test_faulthandler.py", line 60, in get_output
process = script_helper.spawn_python('-c', code, pass_fds=pass_fds)
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\test\script_helper.py", line 136, in spawn_python
**kw)
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\subprocess.py", line 855, in __init__
restore_signals, start_new_session)
File "C:\buildbot.python.org\3.x.kloth-win64\build\lib\subprocess.py", line 1096, in _execute_child
assert not pass_fds, "pass_fds not supported on Windows."
AssertionError: pass_fds not supported on Windows. |
Or we could reuse the file created by filename in subprocess? if filename:
file = open(filename, "wb")
if use_fd:
file = file.fileno()
else:
file = None In this case, we need to pass two arguments(both filename and a bool use_fd) to check_xxx functions. |
New changeset 211e29335e72 by Victor Stinner in branch 'default': |
I commited a fix to repair Windows buildbots.
I tried to pass a file descriptor from the parent to the child Your solution looks simple. Would you like to work on a patch? |
The last approach I proposed requires some change in "template code" of check_xxx methods. To make it better, we can add a bool parameter to the check_xxx functions, True value indicating a fd test. If a filename is given at the same time, then a fd can get from that file. Otherwise the fd should be sys.stderr.fileno(). e.g. # file can be file-object, fd or None The fd-passing approach can co-exist with this one. However it will make "template code" more complex. So I suggest just use one approach to write these fd tests. I will work on a patch(based on tip) at this weekend. |
I attached a patch that implements the solution described above. |
I reviewed issue23566_fd_tests.patch . |
The updated patch refactored test code a little bit according to the latest review comments by Victor. |
@Haypo, would you review issue23566_fd_tests_v2.patch? It's been a time since the last update of it. However I think the fd tests on windows is just fine to be skipped. So what's the next plan? Shall we continue to work on it or just resolve this issue? |
issue23566_fd_tests_v2.patch makes test_faulthandler.py a little more complex. It's maybe better to just skip tests on Windows, the code is already well tested on other platforms, and faulthandler.c doesn't contain code specific to Windows when handling file descriptors. I close the issue, thanks for your patches Wei Wu! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: