waiting on an event blocks all signals

alan alangrow at gmail.com
Sat May 17 16:31:18 EDT 2008


On May 17, 3:06 pm, Jean-Paul Calderone <exar... at divmod.com> wrote:
> On Sat, 17 May 2008 12:49:54 -0700, John Schroeder <jschr... at gmail.com> wrote:
> >On Sat, May 17, 2008 at 12:32 PM, alan <alang... at gmail.com> wrote:
>
> >> This ignores CTRL-C on every platform I've tested:
>
> >> python -c "import threading; threading.Event().wait()"
> >> ^C^C^C^C
>
> >> It looks to me like all signals are masked before entering wait(). Can
> >> someone familiar with the internals explain and/or justify this
> >> behavior? Thanks,
>
> >^C only kills the main thread.  Use Control-Break to kill all threads.
>
> Look at that program.  It's single-threaded.  Where do you think the ^C
> is going? :)
>
> Jean-Paul

Look at this program which is also "single-threaded." Clearly,
python's doing something special. I'm hoping someone can tell me what,
and why.

/*
  pthreadsig.c

  $ gcc pthreadsig.c -lpthread
  $ ./a.out
  ^C
  $
*/

#include <pthread.h>

int main(int argc, char** argv) {
  int rc = 0;

  pthread_mutex_t mtx;
  pthread_cond_t cond;
  pthread_mutex_init(&mtx, 0);
  pthread_cond_init(&cond, 0);

  pthread_mutex_lock(&mtx);
  rc = pthread_cond_wait(&cond, &mtx);
  pthread_mutex_unlock(&mtx);

  return rc;
}



More information about the Python-list mailing list