PyDispatcher question

Jorgen Bodde jorgen.maillist at gmail.com
Thu Apr 5 13:46:20 EDT 2007


Hi all,

Hopefully someone can help me. I am fairly new to Python, and I am
looking into PyDispatcher. I am familiar with the C++ sigslot variant,
and I wonder how similar PyDispatches is. I run in to the following
'problem' (pseudo code, untested here)

import pydispatch.dispatcher

class A:
  def __init__(self):
    dispatcher.connect(self.someSignal, signal = 1)

  def someSignal(self):
    print 'Hello world'

obj = A()

# send a trial signal

dispatcher.send(signal = 1)
>>> Hello world

# now for the catch, how to clean up?
# if I do:
obj = None  # clean up

dispatcher.send(signal = 1)
>>> Hello world

The object still extists... Which is logical, the method is still
bound to the signal, and the object itself is not yet deleted. Is
there an elegant way to delete the object and let the signal unbind
itself? Or do I need to do this in the destructor of the object? AFAIK
there is no real destructor in Python?

Do I need to do it differently? Or is there a better signal mechanism to use?

Any help is appreciated!
- Jorgen



More information about the Python-list mailing list