开发者

Ctrl-C doesn't interrupt semaphore.acquire

while True:
    try:
        queries_semaphore.acquire()
        query = queries.pop(0)
     开发者_JAVA技巧   # Do some stuff ...
        info('Query executed: `%s\'' % str(query))
    except KeyboardInterrupt:
        okay('quit')
        break

The problem is that KeyboardInterrupt is raised only after queries_semaphore.acquire() returns, so a user isn't able to break the program with Ctrl-C. What's a good solution in this case?


I would create another thread for queries_semaphore.acquire() part and leave main thread for interaction with user. If user hit Ctrl-C then you should unblock working thread by setting semaphore and finish it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜