archive mirror
 help / color / mirror / Atom feed
From: Simon Marchi via lttng-dev <>
To: Rocky Dunlap <>,
Subject: Re: bt2 python - accessing component instances added to graph
Date: Mon, 30 Mar 2020 09:45:30 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On 2020-03-30 1:24 a.m., Rocky Dunlap via lttng-dev wrote:
> I noticed that when I add a component to a bt2 graph, e.g.:
> sink = g.add_component(SinglePETSink, "sink"+str(idx))
> The return value "sink" is not actually an instance of SinglePETSink (which has been defined as a local Python class).  How do I get to the instance of SinglePETSink that was created?

If I understand your question correctly: this is actually on purpose to preserve
encapsulation of each component: the user of the graph has the control on the
component when creating it, it can pass parameters to it.  But after that, it
should not be able to go play with the internals of the component.  The `self`
object that has access to the component's state is only available when the
component's methods are called.

So when the user of the graph adds a component, it only receives a generic
component object, which can only be used to access public properties (including
a public view of its ports, that you can use to connect them).

Of course, you can always get around this with a global variable, doing like
this in the component's init:

  global my_component
  my_component = self

But hopefully you won't need to.  If you explain what you are trying to achieve,
we can see if there's a proper way to do it using the existing API.

lttng-dev mailing list

  reply	other threads:[~2020-03-30 13:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-30  5:24 Rocky Dunlap via lttng-dev
2020-03-30 13:45 ` Simon Marchi via lttng-dev [this message]
     [not found]   ` <>
     [not found]     ` <>
2020-03-30 20:41       ` Rocky Dunlap via lttng-dev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \
    --subject='Re: bt2 python - accessing component instances added to graph' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).