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

svn path=/main/branches/2.1.2/; revision=9600

pym/elog_modules/mod_mail_summary.py

index 50e8171df4d8c3df2d18e2982af51ee671ad2167..7d34a4e0b318735fd472f30078915a0c0a383ce4 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)