Handle the problem with Ctrl-C not working if it's done before any connections are made.

This commit is contained in:
Jeremy Fincher 2004-08-21 07:12:39 +00:00
parent 4027d2a171
commit de1673e606

View File

@ -70,6 +70,7 @@ def main():
# We schedule this event rather than have it actually run because if there # We schedule this event rather than have it actually run because if there
# is a failure between now and the time it takes the Owner plugin to load # is a failure between now and the time it takes the Owner plugin to load
# all the various plugins, our registry file might be wiped. That's bad. # all the various plugins, our registry file might be wiped. That's bad.
interrupted = False
when = time.time() + conf.supybot.upkeepInterval() when = time.time() + conf.supybot.upkeepInterval()
schedule.addEvent(world.upkeep, when, name='upkeep') schedule.addEvent(world.upkeep, when, name='upkeep')
world.startedAt = started world.startedAt = started
@ -77,11 +78,22 @@ def main():
try: try:
drivers.run() drivers.run()
except KeyboardInterrupt: except KeyboardInterrupt:
log.info('Exiting due to Ctrl-C at console.') if interrupted:
world.upkeep() # Interrupted while waiting for queues to clear. Let's clear
for irc in world.ircs: # them ourselves.
irc.queueMsg(ircmsgs.quit('Ctrl-C at console.')) for irc in world.ircs:
irc.die() irc._reallyDie()
continue
else:
interrupted = True
log.info('Exiting due to Ctrl-C at console. '
'If the bot doesn\'t exit within a few seconds, '
'feel free to press Ctrl-C again to make it exit '
'without flushing its message queues.')
world.upkeep()
for irc in world.ircs:
irc.queueMsg(ircmsgs.quit('Ctrl-C at console.'))
irc.die()
except SystemExit, e: except SystemExit, e:
s = str(e) s = str(e)
if s: if s:
@ -169,14 +181,12 @@ if __name__ == '__main__':
sys.exit(-1) sys.exit(-1)
if len(args) > 1: if len(args) > 1:
parser.error() parser.error("""Only one configuration option should be specified.""")
elif not args: elif not args:
import supybot.questions as questions parser.error(utils.normalizeWhitespace("""It seems you've given me no
questions.output("""It seems you've given me no configuration file. If configuration file. If you have a configuration file, be sure to tell
you have a configuration file, be sure to tell its filename. If you its filename. If you don't have a configuration file, read
don't have a configuration file, read docs/GETTING_STARTED and follow docs/GETTING_STARTED and follow its directions."""))
its directions.""")
sys.exit(0)
else: else:
registryFilename = args.pop() registryFilename = args.pop()
try: try:
@ -184,8 +194,8 @@ if __name__ == '__main__':
registry.open(registryFilename) registry.open(registryFilename)
shutil.copy(registryFilename, registryFilename + '.bak') shutil.copy(registryFilename, registryFilename + '.bak')
except registry.InvalidRegistryFile, e: except registry.InvalidRegistryFile, e:
s = '%s in %s. ' % (e, registryFilename) s = '%s in %s. Please fix this error and start supybot again.' % \
s += 'Please fix this error and start Supybot again.' (e, registryFilename)
s = textwrap.fill(s) s = textwrap.fill(s)
sys.stderr.write(s) sys.stderr.write(s)
sys.stderr.write(os.linesep) sys.stderr.write(os.linesep)