lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
From: Simon Marchi via lttng-dev <lttng-dev@lists.lttng.org>
To: Rocky Dunlap <dunlap@ucar.edu>, lttng-dev@lists.lttng.org
Subject: Re: bt2 python - accessing component instances added to graph
Date: Mon, 30 Mar 2020 09:45:30 -0400	[thread overview]
Message-ID: <f07941b7-51ae-0f42-2a9b-abcf82e299de@simark.ca> (raw)
In-Reply-To: <CADtyBo4tQxYBFZnk6dqTSkU4OjW2Fxmx0xJrP=ADaCz_YUXf1g@mail.gmail.com>

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.

Simon
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

  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]   ` <CADtyBo6mzBQ3sVUpc4gbxEf7LVsfV+m8oWNMjMdG1gDPsnRR6A@mail.gmail.com>
     [not found]     ` <32146698-0314-1eaf-e422-2c9e088056e7@simark.ca>
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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=f07941b7-51ae-0f42-2a9b-abcf82e299de@simark.ca \
    --to=lttng-dev@lists.lttng.org \
    --cc=dunlap@ucar.edu \
    --cc=simark@simark.ca \
    --subject='Re: bt2 python - accessing component instances added to graph' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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).