Menu

#43 variable problem with package

open-postponed
None
3
2003-05-31
2003-04-16
Jon Griffin
No

It appears that AOLserver is not working with packages
that use variables. I think this is the same ongoing
problem that threads don't reinit their variables on reuse.
This precludes writing namespace code that uses package
scoped vars.

Discussion

  • Zoran Vasiljevic

    Logged In: YES
    user_id=95086

    Can you please give some more details about your problem?
    BTW...
    The 4.0 AOLserver is namespace-savvy, i.e. you can
    use namespaced code in your Tcl scripts. You can even
    make thread blueprint changes from one thread and replicate
    this in other threads using ns_eval command.

     
  • Jon Griffin

    Jon Griffin - 2003-04-16

    Logged In: YES
    user_id=440916

    Here is a snippet:
    namespace eval tools {
    variable page_nums ""
    variable context_markers ""
    variable row ""
    variable row_data ""
    variable column_count 0
    }

    is the package init.

    in my procs I also add:
    variable ::tools::context_markers
    variable ::tools::rows
    variable ::tools::row_data
    variable ::tools::column_count
    etc.

    This is for a pagination/html table proc.
    Depending on which thread I am on (or so it appears), data
    is returned correctly (new thread) or appended (same thread)
    causing duplicates to be returned from the proc. Once the
    thread dies the data is returned normally again.

    If you need more information I can attach the whole namespace.

     
  • Zoran Vasiljevic

    • labels: 101379 -->
    • milestone: 294032 -->
     
  • Zoran Vasiljevic

    Logged In: YES
    user_id=95086

    Ah! Now I understand what you mean.
    Unfurtunately, apart from the global namespace, there is
    no namespace state cleaning between requests running
    on same connection thread. It is a performance issue.
    I will have to see if we can do this fast and in generic
    way. In the meantime, you can always register a Tcl handler
    to be run on connection close and do your own
    garbage collection.

    I will keep this record but will move this to feature requests
    while this is not a bug per-se, strictly speaking.

     
  • Zoran Vasiljevic

    • assigned_to: nobody --> vasiljevic
     
  • Jon Griffin

    Jon Griffin - 2003-04-27

    Logged In: YES
    user_id=440916

    Can you give me a quick example of the garbage collection.
    I am trying to use the record type in tcllib (not the whole
    lib, only the namespace record).

    I hope that you can find a way to clear namespace per thread
    as many new tcl packages support namespaces, and make heavy
    use of variables.

     
  • Zoran Vasiljevic

    Logged In: YES
    user_id=95086

    While not being an ideal solution, you might want to try
    this one:

    ns_atclose {
    package forget YourPackage
    package require YourPackage
    }

    This will instruct the server to perform the above script
    at the end of the connection. The command sequence
    will reload (=re-source) the package file and thus re-init
    the state in current connection thread only. This will not
    however cover (i.e. delete) any variables you have created
    in the package's namespace.

    After some thinking, I'd say that a general Tcl solution to this
    issue is pretty costly in terms of speed and would significanlty
    impact the server's performance. Perhaps, a C-based Tcl
    blueprint snapshot/restore might help, but such thing is not
    available in Tcl API until today.

     
  • Zoran Vasiljevic

    • priority: 5 --> 3
    • status: open --> open-postponed
     
  • Andrew Piskorski

    Logged In: YES
    user_id=43168

    Some people would probably very much like to take advantage
    of AOLserver 4.0's Tcl package support even if it might
    cause poorer performance. So would it not make sense to
    include some sort of configuration option to automatically
    re-set package namespace variables to their initial states,
    even if the implementation is slow?

    Those who take advantage of this feature but find the
    performance a problem, can either work around for each
    specific package, or contribute to a high-performance
    general purpose solution.

     
  • Zoran Vasiljevic

    Logged In: YES
    user_id=95086

    Just to be more precise...

    The package mechanism works very good in 4.0 series.
    The problem appears only when somebody changes the
    package state by adding/deleting procs during runtime
    (which is bad idea anyways), storing private state information
    in package namespace variables and all sorts of such things.
    Generally, there is no easy way to get the virgin state of an
    package without actually dumping the entire interp and reloading
    everything, which is a very time consuming task. You can try this
    with:
    ns_atclose {ns_markfordelete}

    This is of course brute-force but it is unfortunately the only sure
    way of getting the virgin interp/package state. All other efforts to
    genericallysolve this would have to take many compromises and/or
    would therefore be tied to a specific package or usage pattern.

    So, I'm just very skeptic that any half-baked solution would meet
    peoples expectation. The very proper way and IMHO, the only
    practical one is for Tcl people to make a very fast interp blueprint
    getter/setter functions which could be called from within the C-code
    at connection close.
    Maybe we should work towards this instead of trying to get someting
    half-way there. AFAIK, efforts have been already made in this direction
    but I'm not sure what is the latest status of that.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.