James Mills is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

prologic / circuits http://pypi.python.org/pypi/circuits

circuits is a Lightweight Event driven and Asynchronous Application Framework for the Python Programming Language with a strong Component Architecture.

Clone this repository (size: 8.8 MB): HTTPS / SSH
hg clone https://bitbucket.org/prologic/circuits
hg clone ssh://hg@bitbucket.org/prologic/circuits

Issues

#22 Inconsistent handling of accompanying events

Reported by mnlipp (last edited )

I'm still new to circuits, so I may have got it all wrong, but...

The assignment of targets to events is inconsistent. When an event is fired, its target is set as decribed in Event. The targets of the accompanying events specified with attributes "success", "failure", "filter", "start" and "end" remain unchanged, even if they are unspecified (None).

As "start" is fired in the context of fireEvent, however, this event eventually does get the same target as the fired event, the others don't. This results in the inconsistency that "Start(Event)" is targeted, "End(Event)" is not. Of course, this can be avoided by setting the attributes for the accompanying events explicitly for every created Event, but this is tedious (if you have varying targets).

Maybe this should be fixed in fireEvent. However, as I need a solution now, I have derived a class from Event that can be used as base class for events with the behaviour that I want. It might be of interest for others.

Status: resolved Responsible: James Mills Type: enhancement Priority: major
Milestone: none Component: none Version: dev

Attachments

Comments and changes

  1. #1 Alessio Deiana

    written

    This is being revamped in circuits 1.7 Among the changes:

    • start/end are going away
    • success/failure are simple booleans and the triggered channel corresponds to event name + "_success"/"_failure".
  2. #2 mnlipp

    written

    I hope there will be a replacement for "end", I wouldn't know how to handle some problems without being notified when all handlers have been processed.

  3. #3 Alessio Deiana

    written

  4. #4 James Mills

    written

    Is this still an issue in the dev branch?

    --James

  5. #5 James Mills

    written

    • Changed status from new to open.

    ping? --JamesMills / prologic

  6. #6 James Mills

    written

    • Changed status from open to resolved.
    >>> class App(Component):
    ...     def foo(self):
    ...             return 1
    ...     def foo_end(self, e):
    ...             print "end", e
    ...     def foo_success(self, e):
    ...             print "success", e
    ...     def foo_failure(self, e):
    ...             print "failure", e
    ... 
    >>> app = App()
    >>> app.start()
    >>> x = Event.create("foo")
    >>> x
    <foo[.foo] ( )>
    >>> r = app.fire(x)
    >>> r
    <Value (1) result: True errors: False for <foo[*.foo] ( )>
    >>> x.success = True
    >>> x.failure = True
    >>> x.end = True
    >>> r = app.fire(x)
    >>> success <foo[*.foo] ( )>
    end <foo[*.foo] ( )>
    
    >>> r
    <Value (1) result: True errors: False for <foo[*.foo] ( )>
    >>> Debugger().register(app)
    <Debugger/* 30195:MainThread (queued=0) [S]>
    >>> <Registered[*.registered] (<Debugger/* 30195:App (queued=0) [S]>, <App/* 30195:App (queued=0) [R]> )>
    
    >>> r = app.fire(x)
    >>> <foo[*.foo] ( )>
    <fooSuccess[*.foo_success] (<foo[*.foo] ( )> )>
    success <foo[*.foo] ( )>
    <fooEnd[*.foo_end] (<foo[*.foo] ( )> )>
    end <foo[*.foo] ( )>
    
    >>> app.channel = "app"
    >>> r = app.fire(x)
    >>> <foo[app.foo] ( )>
    <fooSuccess[app.foo_success] (<foo[app.foo] ( )> )>
    success <foo[app.foo] ( )>
    <fooEnd[app.foo_end] (<foo[app.foo] ( )> )>
    end <foo[app.foo] ( )>
    
    >>> 
    

    I think you'll find this works rather nicely now in the dev branch (upcoming 1.7 release)

    --JamesMills / prologic

Add comment / attachment

Verification: Please write the text from the image in the box (letters only)

captcha

Is that you, Humanoid? Is this me?