473,797 Members | 3,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

waiting on an event blocks all signals

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,

-Alan
Jun 27 '08 #1
3 3508
On Sat, May 17, 2008 at 2:49 PM, John Schroeder <js******@gmail .comwrote:
^C only kills the main thread. Use Control-Break to kill all threads.
>>
python -c "import threading; threading.Event ().wait()"
^C^C^C^C
There's a single main thread here though. Or am I missing something?
Jun 27 '08 #2
alan schrieb:
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,
They aren't masked. Read the docs:

# Although Python signal handlers are called asynchronously as far as
the Python user is concerned, they can only occur between the ``atomic''
instructions of the Python interpreter. This means that signals arriving
during long calculations implemented purely in C (such as regular
expression matches on large bodies of text) may be delayed for an
arbitrary amount of time.
(http://docs.python.org/lib/module-signal.html)

Which is what is happening here - wait is implemented in C. So the
arriving signal is stored flagged in the interpreter so that the next
bytecode would be the signal-handler set - but the interpreter still
waits for the blocked call.

Diez
Jun 27 '08 #3
On May 18, 9:05 am, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
alan schrieb:
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,

They aren't masked. Read the docs:

# Although Python signal handlers are called asynchronously as far as
the Python user is concerned, they can only occur between the ``atomic''
instructions of the Python interpreter. This means that signals arriving
during long calculations implemented purely in C (such as regular
expression matches on large bodies of text) may be delayed for an
arbitrary amount of time.

(http://docs.python.org/lib/module-signal.html)

Which is what is happening here - wait is implemented in C. So the
arriving signal is stored flagged in the interpreter so that the next
bytecode would be the signal-handler set - but the interpreter still
waits for the blocked call.
If a signal arrives while the thread is in a syscall it will usually
interrupt the syscall. Most code in the interpreter will see the
EINTR error code and check if we have a signal to process, which leads
to raising a KeyboardInterru pt exception. However, most thread
synchronization functions specified in POSIX are not interrupted by
signals, so the interpreter never has a chance do anything. Why would
we care anyway, as Python doesn't let you intentionally interrupt a
non-main thread?
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2189
by: D. Alvarado | last post by:
Hi, Basically, I want to run an action every time I detect a new file appears in a particular directory. I realize I could poll the directory every 5-10 seconds or so, but I was hoping there was a more elegant solution. Is it possible to catch the event that a new file appears or that the size of everything in a directory changes? I am writing this program with gcc on a Windows platform. Thanks in advance, Dave
3
12331
by: Douwe | last post by:
I'm trying to write a piece of C code that has two threads: The first thread waits for a socket connection. The second thread is in a continues cycle waiting for an period of time (lets say 500 ms) or an incomming socket connection (received from the first thread). At this moment I've created two threads were the first one is already waiting for an incomming socket connection. I've also created a timer with timer_create. My problem is that...
6
2901
by: jose luis fernandez diaz | last post by:
Hi, I have a C program running in background in UNIX. From a shell script I want to notify it some events. The easiest way to do it is through signals, but it is not correct because signal are not a event drivent framework. Can anyone give me other straightforward solution ? Thanks, Jose Luis.
4
13268
by: Andreas Müller | last post by:
Hi all, I need to wait for the user to click the mouse: // some code before WaitForMouseClick();// Wait until the user clicks the mouse // go on doing something Under Win32 using C++, you could poll the mouse buttons states. Is this possible using C# and .NET?
3
12602
by: Elhurzen | last post by:
X-No-Archive: Yes >From what I understand, if multiple threads are waiting on a ManualResetEvent after calling WaitOne(), only one thread is guaranteed to be signaled when Set() is called on that ManualResetEvent. How do I ensure that _all_ waiting threads are signaled, without sacrificing any of the functionality or much of the simplicity of ManualResetEvent? Example: SignalingClass:
0
1946
by: Arnaud Debaene | last post by:
Hello all. I've got a bunch of existing, non managed, C++ DLLs that export types with, among other things, public events implemented using the boost::signals library. Now, I need to have these DLL interoperate with managed code. Among others things, the managed code need to be able to register for notification with the boost signals. I've tried different approaches (trying to register a pinned delegate with the boost::signal, etc...),
5
1959
by: Kürþat | last post by:
Hi all, I have a named autoreset event (EventWaitHandle) and two applications one waits on the event and one sets the evet. Application A calls Set method and free a thread in application B. What I want to know is when Set method returns can I assume event is certainly reset? Is this ordering always true : 1- Application A calls Set method (No doubt)
6
5799
by: Lars Uffmann | last post by:
In an event routine, I want to end a certain thread. I am setting a flag that is checked by the thread and causes it to end, when it is set. Then the thread sets a "response" flag, just before exiting. In the event routine, I would like to wait for that response flag, because at that point, I can be sure that the old thread (even if it still is alive between setting the response flag and exiting) will no longer interfere with a subsequent...
1
926
by: Jean-Paul Calderone | last post by:
On Sat, 17 May 2008 12:49:54 -0700, John Schroeder <jschroed@gmail.comwrote: Look at that program. It's single-threaded. Where do you think the ^C is going? :) Jean-Paul
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9536
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.