最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows - While a worker Win32 thread is sleeping, the main thread can't handle a signal - Stack Overflow

programmeradmin2浏览0评论

My Python Win32 code creates a worker thread, which sleeps, and has a signal handler in the main thread to catch Ctrl-C. However, the Ctrl-C response happens only after the worker thread wakes up.

Relevant code:

def main():
    ...
    worker_thread = threading.Thread(target=worker_thread, daemon=True)
    worker_thread.start()
    win32gui.PumpMessages()

def worker_thread():
    while True:
      ...do work...
      sec = ...
      win32api.Sleep(1000 * sec)
      # same results
      # time.sleep(sec)
      win32gui.InvalidateRect(hWindow, rect, True)

if __name__ == '__main__':
    signal.signal(signal.SIGINT, signal_handler)
    main()

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论