I am trying to run the following code (it is a bit simplified):
def RunTests(self): from threading import Thread import signal global keep_running keep_running = True signal.signal( signal.SIGINT, stop_running ) for i in range(0, NumThreads): thread = Thread(target = foo) self._threads.append(thread) thread.start() # wait for all threads to finish for t in self._threads: t.join() def stop_running(signl, frme): global keep_testing keep_testing = False print "Interrupted by the Master. Good by!" return 0 def foo(self): global keep_testing while keep_testing: DO_SOME_WORK();
I expect the user to press Ctrl + C, the program will print a good and message. However, this will not work. Where is the problem?
thank
, Python, , - . "join()" - , . , , , / . , , . 'join()' :
while keep_testing: signal.pause()
:
" ". , Python , . . .
thread.daemon = True start() , .
thread.daemon = True
start()
Source: https://habr.com/ru/post/1771912/More articles:Implementation Problem - functorWhy does this PowerShell script remove svn: mergeinfo from the root directory? - svnWhere can I find the full openejb.xml link? - javafatal error C1017: invalid integer constant expression - visual-c ++Merging a branch with a non-updatable master - gitConfirm uniqueness in combo fields in DataMapper - ruby | fooobar.comКак изменить версию рельсов в Max OS X Snow Leopard? - ruby-on-railsNSTimer or NSThread in the background iOs 4 - iphoneFacebook Authentication - Problem Returning to My iPhone App via Custom URL Scheme - iphoneHow to create a pdf file containing a Marati font using itext? - javaAll Articles