Bug 131080 - Problem with signals in threads in lang/python
Summary: Problem with signals in threads in lang/python
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-python (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-28 13:10 UTC by Andriy Pylypenko
Modified: 2009-03-11 05:57 UTC (History)
0 users

See Also:


Attachments
file.diff (882 bytes, patch)
2009-01-28 13:10 UTC, Andriy Pylypenko
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andriy Pylypenko 2009-01-28 13:10:01 UTC
Almost a year ago I've created an issue in Python's bugtracker but the issue seems to be stuck since then so I'm sending the patch here in hope it could be included in ports collection.

In short there is a problem in the Python that can be seen under FreeBSD and Sun Solaris but not under MacOSX or Linux. The problem is that when a Python program started a thread in a background, then it can be impossible to interrupt the program with Ctrl-C.

The reason why this problem is FreeBSD specific is that the FreeBSD has different order of processing of signals. The  signal handler under FreeBSD fires up in the context of the last started thread, while under Linux signals are processed in the main thread. It should be noted that both behaviors are standards conformant.

This bug at Python bugtracker: http://bugs.python.org/issue1975

Fix: To ensure that signal handler runs in the correct thread context the developer should use pthread_sigmask(). Initially the Python contained this code but starting from Python 2.4 it was thrown away.

The attached patch restores the code that ensures correct execution context of the signal handler code.


Patch attached with submission follows:
How-To-Repeat: Here is an example script. Start it and try to interrupt by hitting ^C.

import time
import select
from threading import Thread

some_time = 6000000 # seconds

class MyThread(Thread):
    def run(self):
        while (True):
            time.sleep(some_time)

t = MyThread()
t.setDaemon(True)
t.start()
while(True):
    select.select([], [], [], some_time)
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2009-01-29 10:40:53 UTC
Responsible Changed
From-To: freebsd-ports-bugs->python

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2009-02-02 11:38:37 UTC
Responsible Changed
From-To: python->freebsd-python

Canonicalize assignment.
Comment 3 dfilter service freebsd_committer freebsd_triage 2009-02-27 01:25:50 UTC
sobomax     2009-02-27 01:25:32 UTC

  FreeBSD ports repository

  Modified files:
    lang/python24        Makefile 
    lang/python25        Makefile 
    lang/python26        Makefile 
  Added files:
    lang/python24/files  patch-Python_thread__pthread.h 
    lang/python25/files  patch-Python_thread__pthread.h 
    lang/python26/files  patch-Python_thread__pthread.h 
  Log:
  Make sure the singal is delivered to the main thread, where python
  runs its signal handlers, not to a random thread that happens to be
  executing at the time when signal arrives. This functionality has been
  lost since Python 2.3, possible cause is that the linux implementation
  of POSIX threads always delivered signal to the main thread. This
  bug results in rather annoying inability to terminate threading script
  with ^C for example and there could be other issues as well.
  
  Bump PORTREVISION.
  
  PR:             ports/131080
  Submitted by:   Andriy Pylypenko <bamby@sippysoft.com>
  Approved by:    MAINTAINER's timeout
  
  Revision  Changes    Path
  1.166     +1 -1      ports/lang/python24/Makefile
  1.1       +30 -0     ports/lang/python24/files/patch-Python_thread__pthread.h (new)
  1.154     +1 -0      ports/lang/python25/Makefile
  1.1       +30 -0     ports/lang/python25/files/patch-Python_thread__pthread.h (new)
  1.156     +1 -1      ports/lang/python26/Makefile
  1.1       +30 -0     ports/lang/python26/files/patch-Python_thread__pthread.h (new)
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2009-03-11 05:56:42 UTC
State Changed
From-To: open->closed

Committed by sobomax 2009-02-27.