Bug #215240 - Use an alarm signal to implement a 60 second timeout in
authorZac Medico <zmedico@gentoo.org>
Sat, 29 Mar 2008 03:40:32 +0000 (03:40 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 29 Mar 2008 03:40:32 +0000 (03:40 -0000)
finalize() in case send_mail() blocks indefinitely.

svn path=/main/trunk/; revision=9588

pym/portage/elog/mod_mail_summary.py

index 40a2484a637396547e7b267cb8e43f298c482db6..8f7f8621795d1698cb7e11e28016b3b756a41492 100644 (file)
@@ -51,8 +51,19 @@ def _finalize(mysettings, items):
 
        mymessage = portage.mail.create_message(myfrom, myrecipient, mysubject,
                mybody, attachments=items.values())
+
+       def timeout_handler(signum, frame):
+               raise PortageException("Timeout in finalize() for elog system 'mail_summary'")
+       import signal
+       signal.signal(signal.SIGALRM, timeout_handler)
+       # Timeout after one minute in case send_mail() blocks indefinitely.
+       signal.alarm(60)
+
        try:
-               portage.mail.send_mail(mysettings, mymessage)
+               try:
+                       portage.mail.send_mail(mysettings, mymessage)
+               finally:
+                       signal.alarm(0)
        except PortageException, e:
                writemsg("%s\n" % str(e), noiselevel=-1)