From owner-freebsd-python@FreeBSD.ORG Mon Apr 22 12:48:33 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 BEFDE70F; Mon, 22 Apr 2013 12:48:33 +0000 (UTC) (envelope-from sbrabez@gmail.com) Received: from mail-wi0-x229.google.com (mail-wi0-x229.google.com [IPv6:2a00:1450:400c:c05::229]) by mx1.freebsd.org (Postfix) with ESMTP id 3032C1877; Mon, 22 Apr 2013 12:48:33 +0000 (UTC) Received: by mail-wi0-f169.google.com with SMTP id h11so4572218wiv.0 for ; Mon, 22 Apr 2013 05:48:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=X9BPGg8cTrh6grlbhTNUirAgjWGrmYFuXEIrMpMq0zY=; b=GG6sn99ms9dCqepp3IgIQ8B624hqNUcw4pCWauFpe1fHyXRRuQzKrudUlkqBMcgZpv M/s6yZc6B1g9fMF4f2JT6e89V4UEOy21wDth4ELXKuES9yAyohVyF41ljMBaRl7/GB4e 5ab/d6Kkvh0K3dcNfGrJ6tsx+tiGQT0hasn+e5tdt61pY+tZecxqf7Bw638ylNoHrsPz ki2OmFXgaTTPPlY5CEG2hbnibTyHD8Avvkpv9kL42YXJnH478G/xYx9P6dRcA2fMs1zY idbxkVqhjGWoKpYJ3+EDWbns1WK4GD51/bAPowbvHJzXRPH/vQPqlpRfnhzeje3Iw6hk qdSA== X-Received: by 10.194.83.33 with SMTP id n1mr52265983wjy.7.1366634912244; Mon, 22 Apr 2013 05:48:32 -0700 (PDT) Received: from ogoshi.int.nbs-system.com (0xd0.org. [188.165.222.46]) by mx.google.com with ESMTPS id s2sm21921305wib.4.2013.04.22.05.48.30 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Apr 2013 05:48:31 -0700 (PDT) Sender: Sofian Brabez Date: Mon, 22 Apr 2013 14:48:28 +0200 From: Sofian Brabez To: Gabor Pali Subject: Re: Python 2.x Threading on FreeBSD Message-ID: <20130422124828.GA35213@ogoshi.int.nbs-system.com> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="opJtzjQTFsWo+cga" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: python@freebsd.org 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: Mon, 22 Apr 2013 12:48:33 -0000 --opJtzjQTFsWo+cga Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Apr 21, 2013 at 07:00:10PM +0200, Gabor Pali wrote: > Hi there, >=20 > 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. >=20 > 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]. >=20 > So could you please fix the lang/python2{6,7} ports by removing the > following part from the files/patch-Python_thread__pthread.h: >=20 > 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_SUPPOR= TED) > 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_SUPPOR= TED) > 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_SUPPOR= TED) > 54 pthread_attr_destroy(&attrs); > 55 #endif >=20 > 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. >=20 >=20 > 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. >=20 > [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= =2Ehtml > [6] https://docs.google.com/viewer?a=3Dv&q=3Dcache:fHDVpJgZl7sJ:www.dabea= z.com/python/GIL.pdf+&hl=3Den&gl=3Dau&pid=3Dbl&srcid=3DADGEESg1OQ8O8lXMSVYr= J813iuu6X-G4539buVO20VRwFvGewPv3PJXWVGen_wQi_SpbL4rIOmfQEwiDyPUJnm8NpIBNObB= qmeXRUd7W3hH3W2AcdeRCrT3zK1bnmA4ZeqoJJbalUZeS&sig=3DAHIEtbTvKZ9pjSW3mbITlDq= XRDYovlYrew > (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" Hi Gabor, I had a look in the upstream thread header in the Python source code, and It appears they remove it too in current [1] and 2.7 branch=A0[2]. I also heavily advice to stay closer to the upstream version, i.e.remove patches they are unneeded anymore or create undefined behaviour. +1 to get rid off. In our ports we have to remove the patch files/patch-Python_thread__pthread.h in port lang/python2{6,7} and ask an exp-run. Regards [1] http://hg.python.org/cpython/file/3bfe8327612a/Python/thread_pthread.h [2] http://hg.python.org/cpython/file/32a5de0e91d5/Python/thread_pthread.h -- Sofian Brabez --opJtzjQTFsWo+cga Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iEYEARECAAYFAlF1MZwACgkQc2NR9CSH5X7iZwCgpR6UzPQnqXFvCf96IOQBt57V unQAoIlmTwdgkci1CDXxw6oLntpWXUnQ =Wi4S -----END PGP SIGNATURE----- --opJtzjQTFsWo+cga--