From owner-freebsd-python@FreeBSD.ORG Sun Apr 21 17:00:11 2013 Return-Path: Delivered-To: python@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id D178E5E4 for ; Sun, 21 Apr 2013 17:00:11 +0000 (UTC) (envelope-from pali.gabor@gmail.com) Received: from mail-oa0-f49.google.com (mail-oa0-f49.google.com [209.85.219.49]) by mx1.freebsd.org (Postfix) with ESMTP id A5022191A for ; Sun, 21 Apr 2013 17:00:11 +0000 (UTC) Received: by mail-oa0-f49.google.com with SMTP id j1so2740352oag.8 for ; Sun, 21 Apr 2013 10:00:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:date:x-google-sender-auth:message-id :subject:from:to:content-type:content-transfer-encoding; bh=3QEUoRCR2Syac3ha+SSPiOJTPdTYjhCleY3Yc2ddPtw=; b=CxhQ7eOkfL0Th1PMGmH6U28YlgAK+v83SrTA+SosmvrKaYSmkV+eraNT+ZSQjFSRmu KCGMM8NbgaQAwLC9J1GJ1GAN4lIzRUggpQ+Q/jPmCtkBo/kghzZb0tQkdSTnj+WBclJj SdYNkSHMT56OkM5u4xeySl43akB4URjjqb8+r/Ii16HP0bXZLHdWWp4nWDjUhp1M84Wt d1BX+KsMPegKU9WaekzVGC1nn2uIktKd/sOMfp4F6fvUUufnn1p+dicPLO5am/U6TqH3 /sDunSEnxsVQtI0OjklUkd5dDf5PM2yfPeBcyVLzOtXIOpA6qIjeRRs3YJVPq99k1klo gqBw== MIME-Version: 1.0 X-Received: by 10.60.92.41 with SMTP id cj9mr8431452oeb.31.1366563610793; Sun, 21 Apr 2013 10:00:10 -0700 (PDT) Sender: pali.gabor@gmail.com Received: by 10.182.28.197 with HTTP; Sun, 21 Apr 2013 10:00:10 -0700 (PDT) Date: Sun, 21 Apr 2013 19:00:10 +0200 X-Google-Sender-Auth: v_cgOfnTxGPv2LvzlZfrlqmVeog Message-ID: Subject: Python 2.x Threading on FreeBSD From: Gabor Pali To: python@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-python@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: FreeBSD-specific Python issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Apr 2013 17:00:11 -0000 Hi there, Recently I ran into an issue where multi-threaded programs with signals cannot be run correctly from a thread in Python 2.x with the vanilla lang/python27 port, c.f. [1]. As I wrote in the corresponding ticket, the possible cause for this is that threading has been patched back in 2009 [2] so I recommended to use GNU pth instead. However, I managed to catch koobs on IRC yesterday and we continued to pursue the reason for this problem further. The aforementioned patch was a result of handling ports/131080 [3] where the submitter states that this is a solution to a problem where Ctrl+C cannot be handled when the main thread is blocked by waiting for another thread. Note this patch has been rejected upstream [4]... actually because this is not a bug but a feature [5][6]. So could you please fix the lang/python2{6,7} ports by removing the following part from the files/patch-Python_thread__pthread.h: 31 @@ -149,6 +153,7 @@ 32 { 33 pthread_t th; 34 int status; 35 + sigset_t set, oset; 36 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTE= D) 37 pthread_attr_t attrs; 38 #endif 39 @@ -177,6 +182,8 @@ 40 #if defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) 41 pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM); 42 #endif 43 + sigfillset(&set); 44 + SET_THREAD_SIGMASK(SIG_BLOCK, &set, &oset); 45=09 46 status =3D pthread_create(&th, 47 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTE= D) 48 @@ -188,6 +195,7 @@ 49 (void *)arg 50 ); 51=09 52 + SET_THREAD_SIGMASK(SIG_SETMASK, &oset, NULL); 53 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTE= D) 54 pthread_attr_destroy(&attrs); 55 #endif Note that I have tested this modification with the program in the referenced PR and with the program which is failing and both indeed worked as described in the cited sources. PS_1: Thanks koobs for helping me with tracking down this issue! PS_2: Please CC in your replies as I am not on this list. [1] http://hackage.haskell.org/trac/ghc/ticket/7652 [2] http://svnweb.freebsd.org/ports?view=3Drevision&revision=3D230031 [3] http://www.freebsd.org/cgi/query-pr.cgi?pr=3D131080 [4] http://bugs.python.org/issue1975 [5] http://www.regexprn.com/2010/05/killing-multithreaded-python-programs.h= tml [6] https://docs.google.com/viewer?a=3Dv&q=3Dcache:fHDVpJgZl7sJ:www.dabeaz.= com/python/GIL.pdf+&hl=3Den&gl=3Dau&pid=3Dbl&srcid=3DADGEESg1OQ8O8lXMSVYrJ8= 13iuu6X-G4539buVO20VRwFvGewPv3PJXWVGen_wQi_SpbL4rIOmfQEwiDyPUJnm8NpIBNObBqm= eXRUd7W3hH3W2AcdeRCrT3zK1bnmA4ZeqoJJbalUZeS&sig=3DAHIEtbTvKZ9pjSW3mbITlDqXR= DYovlYrew (pages 21, 22, 25)