473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Interrupting a running python thread

I have embedded a python console in a plugin to a Windows application.
I do not control the application, but the plugin is mine. Since the
application is not thread-safe, I am push()-ing each line onto a
code.InteractiveConsole on the GUI thread. This has the downside that a
silly mistake that creates an infinite loop also hangs the GUI, thus
preventing you from saving your work or exiting the application in any
normal fashion.

As a workaround, I've installed a console handler that calls
thread.interrupt_main() when control-c is pressed. I should point out
that this is done on a new thread. Unfortunately this doesn't work at
all. Without returning from the last call to InteractiveConsole.push()
or catching the KeyboardInterrupt, the interpreter explodes with a "no
current thread" fatal error.

I've tried the exact same code at "the real" python prompt and that
happily prints:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
KeyboardInterrupt
>>>
The code used is this infinite loop:

a = 0
while a == 0: b = a + 2

What's the secret? The only use of SetConsoleCtrlHandler I could find
in the CPython source didn't make me much wiser.

Johan

Aug 25 '06 #1
0 1300

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

Similar topics

0
by: eparker | last post by:
Hello! I'm new to this list, so please be gentle. :) I've been scouring the net for an answer to this, as well as trying to get a little demo running, but to no avail, so I'm going to plead...
2
by: J. W. McCall | last post by:
I'm working on a MUD server and I have a thread that gets keyboard input so that you can enter commands from the command line while it's in its main server loop. Everything works fine except that...
1
by: stephan | last post by:
Hi, Im am using PyRun_SimpleString() inside a BCB 5.0 GUI app on win32. All works fine. The PyRun_SimpleStript() runs a piece of python code which calls often a callback function to...
0
by: Dirk Runge | last post by:
Hi! I have embedded Python in an C++ App. The Python-Interpreter is running in its own Thread (I'm using PThreads). I use PyRun_SimpleString to run Python-Code that the user entered in an...
6
by: seb | last post by:
Hi, I am using pygtk for the first times. I am wondering what would be the best "pattern" to interface pygtk with a thread. The thread is collecting informations (over the network for...
13
by: michael sorens | last post by:
I have a lengthy sequence of operations that are executed and reported on in a status window in a Windows Form application. Some work is done by background threads but other work is not. I am...
3
by: Florian Demmer | last post by:
Hi! I have a number of ftp uploads running in parallel using ftplib.storbinary and threading and in case one of them fails I need to interrupt all the others (but not exit the program...
4
by: jehugaleahsa | last post by:
Hello: Is there a way to prevent one event from firing while another event is already being fired? I have a tool that extracts media from web pages and it has multiple events firing when the...
8
by: geert | last post by:
Hi all, I have a mac mini running maocosx 10.5 leopard I want to deploy a django project on. My backend is MySQL, and I have it running as a 64- bit app. Of course, apache2 is also running as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.