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.
精彩评论