Accessing objects at runtime.

Discussion in 'Python' started by jacopo, Sep 10, 2009.

  1. jacopo

    jacopo Guest

    I have a system comprising many objects cooperating with each others.
    (For the time being, everything is running on the same machine, in the
    same process but things might change in the future). The system starts
    a infinite loop which keeps triggering operations from the
    instantiated objects.

    I would like to find a way to inspect the objects at run time. In
    other words I would like to check certain attributes in order to
    understand in which status the object is. This of course without
    having to stop the system and resume it after the checking is
    finished.

    I would be grateful to any suggestion.
    Regads,
    Jacopo
    jacopo, Sep 10, 2009
    #1
    1. Advertising

  2. jacopo:
    >
    > I would like to find a way to inspect the objects at run time. In
    > other words I would like to check certain attributes in order to
    > understand in which status the object is.


    What exactly do you want to know? The names of existing attributes or
    their content? The latter is probably obvious to you and the former is
    easy, too. See hasattr, getattr and isinstance.

    J.
    --
    I lust after strangers but only date people from the office.
    [Agree] [Disagree]
    <http://www.slowlydownward.com/NODATA/data_enter2.html>

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEARECAAYFAkqpFgsACgkQ+AfZydWK2zlkKACghMNgoxAlbO9s+5S32oyfL6lM
    DQYAmwUofsl5DUYaaUu+KKaSN4PFvR1A
    =AMaE
    -----END PGP SIGNATURE-----
    Jochen Schulz, Sep 10, 2009
    #2
    1. Advertising

  3. jacopo

    jacopo Guest


    >
    > What exactly do you want to know? The names of existing attributes or
    > their content? The latter is probably obvious to you and the former is
    > easy, too. See hasattr, getattr and isinstance.


    I want to know the value of the attributes.
    What you suggest works when the program stops, objects are still in
    memory and I could inspect all I want. BUT I don’t want to stop the
    system. So even the shell would be blocked to type something.

    Thanks,
    Jacopo
    jacopo, Sep 10, 2009
    #3
  4. jacopo:
    >
    >> What exactly do you want to know? The names of existing attributes or
    >> their content? The latter is probably obvious to you and the former is
    >> easy, too. See hasattr, getattr and isinstance.

    >
    > I want to know the value of the attributes.
    > What you suggest works when the program stops, objects are still in
    > memory and I could inspect all I want. BUT I don’t want to stop the
    > system. So even the shell would be blocked to type something.


    Ah, now I get it: you want to attach to a running process and inspect it
    interactively? -Sorry, then I cannot answer you question.

    J.
    --
    When I get home from the supermarket I don't know what to do with all the
    plastic.
    [Agree] [Disagree]
    <http://www.slowlydownward.com/NODATA/data_enter2.html>

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEARECAAYFAkqpH2cACgkQ+AfZydWK2zkZQgCeMwUbh15ewmll9tOXyNpyTWlF
    lH4AmwVwUVsMuNrkcWJNt5wrWZ4/TH1c
    =l2Tm
    -----END PGP SIGNATURE-----
    Jochen Schulz, Sep 10, 2009
    #4
  5. jacopo

    Gary Duzan Guest

    In article <>,
    jacopo <> wrote:
    >I have a system comprising many objects cooperating with each others.
    >(For the time being, everything is running on the same machine, in the
    >same process but things might change in the future). The system starts
    >a infinite loop which keeps triggering operations from the
    >instantiated objects.
    >
    >I would like to find a way to inspect the objects at run time. In
    >other words I would like to check certain attributes in order to
    >understand in which status the object is. This of course without
    >having to stop the system and resume it after the checking is
    >finished.


    You might consider running a BaseHTTPServer in a separate thread
    which has references to your objects of interest and exporting the
    data through a web interface. Using a RESTful approach for mapping
    URLs to objects within your system, a basic export of the data can
    be as simple as printing out HTML strings with interpolated data.
    (I recently did this in a couple hundred lines of code for a small
    example handling a few resource types.) Fancier solutions could
    pull in any of the freely available template engines or other web
    framework pieces. When you move to different processes and/or
    machines, the access method can remain the same by varying the port
    and/or hostname in the URL.

    Good luck...

    Gary Duzan
    Motorola H&NM
    Gary Duzan, Sep 10, 2009
    #5
  6. jacopo

    jacopo Guest


    >    You might consider running a BaseHTTPServer in a separate thread
    > which has references to your objects of interest and exporting the
    > data through a web interface. Using a RESTful approach for mapping
    > URLs to objects within your system, a basic export of the data can
    > be as simple as printing out HTML strings with interpolated data.



    Thank you Gary,

    just to be sure I understood correctly:
    with this solution, in order to inspect an object I would have to load
    a web page at a specific URL. That URL,
    through a separate thread, would access the object on the fly and
    display the content in a web page?!
    Is there a reason to link objects to different URLs or I could link
    many of them to the same URL?

    Thanks, Jacopo
    jacopo, Sep 14, 2009
    #6
  7. why not just pawn your processing loop off onto a child thread and
    give yourself a hook (function) that you can call that return whatver
    info you what. Run the script in ipython, problem solved.


    On Mon, Sep 14, 2009 at 7:57 AM, jacopo <> wrote:
    >
    >>    You might consider running a BaseHTTPServer in a separate thread
    >> which has references to your objects of interest and exporting the
    >> data through a web interface. Using a RESTful approach for mapping
    >> URLs to objects within your system, a basic export of the data can
    >> be as simple as printing out HTML strings with interpolated data.

    >
    >
    > Thank you Gary,
    >
    > just to be sure I understood correctly:
    > with this solution, in order to inspect an object I would have to load
    > a web page at a specific URL. That URL,
    > through a separate thread, would access the object on the fly and
    > display the content in a web page?!
    > Is there a reason to link objects to different URLs or I could link
    > many of them to the same URL?
    >
    > Thanks, Jacopo
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Chris Colbert, Sep 14, 2009
    #7
  8. jacopo

    jacopo Guest

    On Sep 14, 9:54 am, Chris Colbert <> wrote:
    > why not just pawn your processing loop off onto a child thread and
    > give yourself a hook (function) that you can call that return whatver
    > info you what. Run the script in ipython, problem solved.
    >


    thank you Chris, I have just implemented this in a mock example it
    seems to work. Clean and simple!

    Jacopo
    jacopo, Sep 14, 2009
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ilyas
    Replies:
    1
    Views:
    304
    Softwaremaker
    Jul 4, 2003
  2. Hal Vaughan
    Replies:
    11
    Views:
    1,075
    Gordon Beaton
    May 22, 2006
  3. 7stud
    Replies:
    11
    Views:
    662
    Dennis Lee Bieber
    Mar 20, 2007
  4. jacopo

    Accessing objects at runtime.

    jacopo, Sep 10, 2009, in forum: Python
    Replies:
    0
    Views:
    277
    jacopo
    Sep 10, 2009
  5. Derek Basch
    Replies:
    4
    Views:
    177
    -berlin.de
    Aug 16, 2006
Loading...

Share This Page