Opened 15 years ago

Closed 15 years ago

#2692 defect closed fixed (fixed)

before-shutdown triggers are fired multiple times

Reported by: yaubi Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: yaubi, therve Branch:


Using twisted svn, python 2.4 & 2.5

This program:

import os, signal, time
from twisted.internet import reactor, defer
def terminate():
    print "terminating ..."
    d = defer.Deferred()
    # do things that lasts long (eg. database, network, etc.)
    reactor.callLater(1, d.callback, None)
    return d
pid = os.getpid()
if os.fork():
    # parent
    reactor.addSystemEventTrigger('before', 'shutdown', terminate)
    os.kill(pid, signal.SIGTERM)
    os.kill(pid, signal.SIGTERM)

produces the following output:


The terminate() method is ran twice, which is not what is excepted. This may also be reproduced by calling reactor.stop() twice (see 2nd test attached)

Proposed patch is attached below. It involves yet-another reactor attribute to discard subsequent signals. It also raises a specialized exception ReactorAlreadyStopped if reactor.stop() is manually called multiple times.

I tryied hard to provide unit tests with this ticket, but unfortunately didn't succeed as it involves reactor.stop (and I'm also not so used to unit tests yet, which is a shame, I know)

See also:

Attachments (3) (721 bytes) - added by yaubi 15 years ago.
1st test, with signals (2.8 KB) - added by yaubi 15 years ago.
2nd test, with reactor.stop
patch (2.5 KB) - added by yaubi 15 years ago.
Proposed patch

Download all attachments as: .zip

Change History (6)

Changed 15 years ago by yaubi

Attachment: added

1st test, with signals

Changed 15 years ago by yaubi

Attachment: added

2nd test, with reactor.stop

Changed 15 years ago by yaubi

Attachment: patch added

Proposed patch

comment:1 Changed 15 years ago by Jean-Paul Calderone

Owner: changed from Glyph to Jean-Paul Calderone

Thanks. I think I know how to write a unit test for this. I've been making some related fixes for #2509. I'll probably fix this issue as part of that ticket, too.

comment:2 Changed 15 years ago by therve

Resolution: fixed
Status: newclosed

That has been fixed with #2509.

comment:3 Changed 11 years ago by <automation>

Owner: Jean-Paul Calderone deleted
Note: See TracTickets for help on using tickets.