On Sun, Apr 21, 2013 at 07:00:10PM +0200, 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-unsubscr...@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 [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

Attachment: pgpV92ZqbvaFn.pgp
Description: PGP signature

Reply via email to