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.

Author neologix
Recipients neologix, vstinner
Date 2011-07-02.08:31:22
SpamBayes Score 5.6621374e-15
Marked as misclassified No
Message-id <CAH_1eM2jHVU2r527q0njnEgKXGBc4FNS=vet9mF19KNaTddEsg@mail.gmail.com>
In-reply-to <1309565759.32.0.476623553404.issue12469@psf.upfronthosting.co.za>
Content
>> On FreeBSD 6, os.kill(os.getpid(), signum) calls immediatly
>> the signal handler before the creation of the first thread (...),
>> whereas the signal handler is called "later" (when exactly?) after
>> the creation of the first thread (default after my commit).
>
> It looks like a kernel/libc bug. At least, it doesn't conform to POSIX.1-2001. Extract of the Linux manual page of the kill function (syscall):
>

Yes, that's definitely a kernel/libc bug, like  #12392.

> I see two options:
>
>  - revert my commit and fix #12392 (test_signal) differently
>  - skip test_register, test_register_file, test_register_threads and test_stack_overflow can on freebsd6
>
> I prefer to revert my commit because it introduced an unexpected behaviour on signal handling. It calls the signal handler later when the process sends a signal to itself, even if the application don't use threads.
>

I'm also in favor of reverting this commit.

> The new fix for #12392 is to ensure that at least one thread was created. We can for example use the following code at the beginning of test_signal:
>
> if sys.platform in ('freebsd5', 'freebsd6'):
>  # On FreeBSD6, pthread_kill() doesn't work on the main thread
>  # before the creation of the first thread
>  import threading
>  t = threading.Thread(target=lambda: None)
>  t.start()
>  t.join()
>
> Then test_signal.test_pthread_kill_main_thread() should be skipped or patched for freebsd6.
>

Yes.

By the way, this also explains the test.test_signal.WakeupSignalTests
failures we had on FreeBSD 6.4.
Here's what I wrote in see http://bugs.python.org/issue8407#msg137382 :

"""
"""
======================================================================
FAIL: test_signum (test.test_signal.WakeupSignalTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/home/db3l/buildarea/3.x.bolen-freebsd/build/Lib/test/test_signal.py",
line 272, in test_signum
    self.check_signum(signal.SIGUSR1, signal.SIGALRM)
  File "/usr/home/db3l/buildarea/3.x.bolen-freebsd/build/Lib/test/test_signal.py",
line 238, in check_signum
    self.assertEqual(raised, signals)
AssertionError: Tuples differ: (14, 30) != (30, 14)

First differing element 0:
14
30

- (14, 30)
+ (30, 14)
"""

This means that the signals are not delivered in order.
Normally, pending signals are checked upon return to user-space, so
trip_signal should be called when the kill syscall returns, so signal
numbers should be written in order to the wakeup FD (and here it looks
like the lowest-numbered signal is delivered first).
You could try adding a short sleep before the second kill (or just
pass unordered=True to check_signum, but in that case we don't check
the correct ordering).
"""

Since signals are not delivered synchronously when the kill() syscall
returns, they are delivered later, and the order is not preserved.

The patch above (creating a dummy thread at the beginning of
test_signal) should fix this, so you might be able to revert
http://hg.python.org/cpython/rev/29e08a98281d .
History
Date User Action Args
2011-07-02 08:31:23neologixsetrecipients: + neologix, vstinner
2011-07-02 08:31:22neologixlinkissue12469 messages
2011-07-02 08:31:22neologixcreate