Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Apr 2013 19:00:10 +0200
From:      Gabor Pali <pgj@FreeBSD.org>
To:        python@freebsd.org
Subject:   Python 2.x Threading on FreeBSD
Message-ID:  <CAHnG2CxDbP9CVOM-sWvzpYA%2Bm5sH02QywhYo6mdRrQ4WnMHQRg@mail.gmail.com>

index | next in thread | raw e-mail

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)


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAHnG2CxDbP9CVOM-sWvzpYA%2Bm5sH02QywhYo6mdRrQ4WnMHQRg>