タグ付けされた質問 「keyboardinterrupt」

10
Pythonのマルチプロセッシングプールでのキーボード割り込み
PythonのマルチプロセッシングプールでKeyboardInterruptイベントを処理するにはどうすればよいですか?以下に簡単な例を示します。 from multiprocessing import Pool from time import sleep from sys import exit def slowly_square(i): sleep(1) return i*i def go(): pool = Pool(8) try: results = pool.map(slowly_square, range(40)) except KeyboardInterrupt: # **** THIS PART NEVER EXECUTES. **** pool.terminate() print "You cancelled the program!" sys.exit(1) print "\nFinally, here are the results: …

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.