Opened 7 years ago

Closed 7 years ago

#7597 closed enhancement (not a bug)

Send arbitrary parameters to functors

Reported by: robinson Owned by: atagar
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Keywords: events
Cc: Actual Points:
Parent ID: #7328 Points:
Reviewer: Sponsor:

Description

In event-handling it would be nice to include custom parameters to pass to the receiving functor.

Child Tickets

Change History (3)

comment:1 Changed 7 years ago by robinson

As an example:

  def listener(event, channel):
    channel.send(event)

  chan1, chan2 = Pipe()
  with Controller as controller:
    controller.authenticate()
    controller.add_event_listener(listener, [CIRC, STREAM], chan1)
    time.sleep(5)

comment:2 Changed 7 years ago by atagar

Hi robinson. Wouldn't it be better to use a partial rather than having the Controller track the extra arguments?

import functools

def listener(channel, event):
  channel.send(event)

chan1, chan2 = Pipe()
with Controller as controller:
  controller.authenticate()
  controller.add_event_listener(funtools.partial(listener, chan1), [CIRC, STREAM])
  time.sleep(5)

comment:3 in reply to:  2 Changed 7 years ago by robinson

Resolution: not a bug
Status: newclosed

Replying to atagar:

Wouldn't it be better to use a partial rather than having the Controller track the extra arguments?

Yes, it would. I keep forgetting about partial. I'm closing this ticket as not a bug.

Note: See TracTickets for help on using tickets.