This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Proper return status of os.WNOHANG is not always (0, 0)
Type: Stage:
Components: Documentation Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: docs@python Nosy List: davin, docs@python, eradman
Priority: normal Keywords:

Created on 2014-06-17 16:23 by eradman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg220843 - (view) Author: Eric Radman (eradman) Date: 2014-06-17 16:23
The documentation for the WNOHANG flag (https://docs.python.org/3.4/library/os.html#os.WNOHANG) suggests that a return value of (0, 0) indicates success. This is not always true, the second value may contain a value even on success. On OpenBSD 5.5 this is an exaple status of a process that is still running:

pid, status = os.waitpid(pid, os.WNOHANG)
(0, -168927460)

It would be more accurate to say that if pid==0 then the process is running and that status is platform dependent.
msg242128 - (view) Author: Davin Potts (davin) * (Python committer) Date: 2015-04-27 17:02
The man pages for waitpid on OpenBSD 5.x do not suggest any meaningful value will be returned in status when WNOHANG is requested and no child processes have anything to report.

The following session attempts to exercise os.waitpid using Python 2.7.9 on an OpenBSD 5.3 i386 system:
>>> import os
>>> os.spawnl(os.P_NOWAIT, '/bin/sleep', 'sleep', '10')
19491
>>> os.waitpid(-1, os.WNOHANG)
(0, 0)
>>> os.waitpid(-1, os.WNOHANG)   # wait a few seconds, try again
(0, 0)
>>> os.waitpid(-1, os.WNOHANG)   # waited long enough for sleep to exit
(19491, 0)
>>> os.waitpid(-1, os.WNOHANG)   # at this point, no children remain
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 10] No child processes


Can you provide any further information, like:
* OpenBSD docs that explain that we should expect non-zero values for status coming from waitpid?
* Example Python code to provoke the behavior originally described?
* Other suggestion of why OpenBSD's waitpid, which itself depends upon wait4, when called (the way Python calls it) with an already initialized status=0 and WNOHANG should return a modified value for status when the child had nothing to report?
msg243104 - (view) Author: Eric Radman (eradman) Date: 2015-05-13 17:02
Thanks for posting some simple examples. 

Here is the commit that I wrote to solve this problem when I encountered it in the wild:

https://bitbucket.org/tk0miya/testing.postgresql/commits/3f145860cfd91e3f03f24b87c4b3b41c3a974037

Closing since I am also not able to reproduce this using a simple example.
History
Date User Action Args
2022-04-11 14:58:05adminsetgithub: 65990
2015-05-13 17:02:35eradmansetstatus: pending -> closed
resolution: works for me
messages: + msg243104
2015-04-27 17:02:43davinsetstatus: open -> pending
nosy: + davin
messages: + msg242128

2014-06-17 16:23:08eradmancreate