473,395 Members | 1,692 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,395 software developers and data experts.

A Question About Handling SIGINT With Threads

I got this to work, but was hoping there was a better way. I was
hoping that I wouldn't have to use globals. I wouldn't doubt that I
could be totally off in what I am doing.

Here is some psuedo-code of what I did:

def main_thread():
# Don't know how to get rid of these guys
global lock
global my_thread

# Set up a signal handler for Ctrl-C
signal.signal(signal.SIGINT, sighdlr)

# Create & start thread
lock = thread.allocate_lock()
lock.acquire()
my_thread = threading.Thread(
target=child_thread,
name='thread_test',
args=(lock,)
my_thread.start()

do_some_work_here()

# Tell thread to stop working
lock.release()

# Wait for child thread to finish
my_thread.join()

def child_thread(lock):

while lock.locked():
do_some_stuff()

do_some_cleanup()

def sighdlr(signum, frame):

# Allow child to finish
lock.release()
my_thread.join()
sys.exit(1)

Jul 18 '05 #1
0 1183

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

Similar topics

0
by: John C. Worsley | last post by:
I've got an extremely inscrutable problem here using Perl's Term::ReadLine::Gnu module. I'm using Perl 5.8.0, readline 4.3 and Term::ReadLine::Gnu 1.14. The problem is specific to catching INT...
2
by: Rookie | last post by:
Hi, I have a program that fork()'s + execlp()'s two children. Later in the program I want to send a signal to the parent(SIGINT) . The parent's signal handler should then send signals to these...
11
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
7
by: Stanley S | last post by:
Hi, Are Signal Handling part of ANSI C? I am not able to find any reference of Sig Handling in Stephen Prata's "C Primer Plus". The usage of signals is to trap errors I guess. (It looks...
4
by: MadSage | last post by:
I currently have a multi-threaded server application with worker threads and a core thread. For all of these threads I have something like the following code: uint32 __stdcall...
0
by: Manlio Perillo | last post by:
Hi. I have tried this script: from ctypes import cdll, c_int from signal import SIGTERM, SIGINT from time import sleep msvcrt = cdll.LoadLibrary("MSVCR71") # is this the lib to use?
1
by: 32Alpha | last post by:
Hi, first post here. First off, this IS a homework assignment for an operating systems class, but the question isn't "how do i do the assignment" but "why is my particular implementation not...
0
by: Marcin Krol | last post by:
Hello everyone, And now for something completely different: signal handling sometimes works, sometimes it doesn't. When I embed following code, it works: count = 0
0
by: Marcin Krol | last post by:
Right, I didn't realize before that Python interpreter has its own signal handling routines. Now I am able to handle signals in Python code, but it still barfs on exit: import time import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.