From owner-freebsd-python@FreeBSD.ORG Mon Apr 22 01:24:45 2013 Return-Path: Delivered-To: python@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 02AB91AA; Mon, 22 Apr 2013 01:24:45 +0000 (UTC) (envelope-from koobs.freebsd@gmail.com) Received: from mail-da0-x22a.google.com (mail-da0-x22a.google.com [IPv6:2607:f8b0:400e:c00::22a]) by mx1.freebsd.org (Postfix) with ESMTP id CDB2F1902; Mon, 22 Apr 2013 01:24:44 +0000 (UTC) Received: by mail-da0-f42.google.com with SMTP id n15so997509dad.15 for ; Sun, 21 Apr 2013 18:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:reply-to:user-agent:mime-version:to :cc:subject:references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=7fcE7xgfTikWQyTWXS3J01PgX7WRRJfVzIOT/utgw3g=; b=UWDLefAXLl1vbiHQLmElH4TiwUcomJMCVxChoagbzpcoyNumST4tJa0bDoaPOqM+cM R333yKwGbpe7WQCWX/n7TatRrnl1qDJAAZSHS7l7rocL1wJmdWNOYldp68Z+Df5ugxt8 txexbgxbCIbQ25VS9K346WAl6DGBQfeD7+iXgoTkTvP4GaGPEEBnmcOrW9WcZYUMVTj+ zKPxqmazzsHmq6Ws+oqy+4CoY2Gd6zimCUzGj23gjhmS6sYfuzSpz9mux7terrAVCFrb GUpMvuZ14bDXno3jAchkXRE1HAgPnQkI87FG1HAYywYGgn1AQijTrX7ZFuNWJ0NG7rIW bmjQ== X-Received: by 10.68.49.193 with SMTP id w1mr29687515pbn.146.1366593883755; Sun, 21 Apr 2013 18:24:43 -0700 (PDT) Received: from [192.168.1.7] (ppp59-167-128-11.static.internode.on.net. [59.167.128.11]) by mx.google.com with ESMTPS id wl5sm24676027pac.18.2013.04.21.18.24.41 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 21 Apr 2013 18:24:42 -0700 (PDT) Message-ID: <51749155.4090305@FreeBSD.org> Date: Mon, 22 Apr 2013 11:24:37 +1000 From: Kubilay Kocak User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 MIME-Version: 1.0 To: python@freebsd.org Subject: Re: Python 2.x Threading on FreeBSD References: In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Gabor Pali X-BeenThere: freebsd-python@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: koobs@FreeBSD.org List-Id: FreeBSD-specific Python issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2013 01:24:45 -0000 On 22/04/2013 3:00 AM, Gabor Pali wrote: > 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_SUPPORTED) > 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 > 46 status = pthread_create(&th, > 47 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) > 48 @@ -188,6 +195,7 @@ > 49 (void *)arg > 50 ); > 51 > 52 + SET_THREAD_SIGMASK(SIG_SETMASK, &oset, NULL); > 53 #if defined(THREAD_STACK_SIZE) || defined(PTHREAD_SYSTEM_SCHED_SUPPORTED) > 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=revision&revision=230031 > [3] http://www.freebsd.org/cgi/query-pr.cgi?pr=131080 > [4] http://bugs.python.org/issue1975 > [5] http://www.regexprn.com/2010/05/killing-multithreaded-python-programs.html > [6] https://docs.google.com/viewer?a=v&q=cache:fHDVpJgZl7sJ:www.dabeaz.com/python/GIL.pdf+&hl=en&gl=au&pid=bl&srcid=ADGEESg1OQ8O8lXMSVYrJ813iuu6X-G4539buVO20VRwFvGewPv3PJXWVGen_wQi_SpbL4rIOmfQEwiDyPUJnm8NpIBNObBqmeXRUd7W3hH3W2AcdeRCrT3zK1bnmA4ZeqoJJbalUZeS&sig=AHIEtbTvKZ9pjSW3mbITlDqXRDYovlYrew > (pages 21, 22, 25) > _______________________________________________ > freebsd-python@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-python > To unsubscribe, send any mail to "freebsd-python-unsubscribe@freebsd.org" > Nice write-up Gabor, and you're welcome. +1 on this and any other patch-removals that get us closer to upstream