Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
command queue

Posted by ardikus (ardikus), 7 July 2004
Hi everyone, I've been having some difficulty modifying the order in which commands are processed. What I am trying to create is a FIFO queue, that takes commands from the user via a button click, and spaces the commands 1 second apart each.

I tried doing this using the vwait command, so that each time the button is clicked, it waits an additional second to execute the command.

When a button is clicked, it runs a proc called SendCommand.

In SendCommand, I have:

incr CQ 1

set placeinline $CQ

set n 0
after 1000 {set n 1}
vwait n

while {$placeinline > 1} {

set m 0
after 1000 {set m 1}
vwait m
incr placeinline -1

}

exec command x

incr $CQ -1

Unfortunately if I click Button A, and then Button B before before command A  is complete, the vwait in command B takes precedence and completes first. I need the commands to be executed in the order in which the buttons are clicked.

Does anyone have any possible suggestions for how to set this up in TCL so that I can evenly space the execution of commands no matter how quickly I click the buttons? Any help is appreciated, and if further clarification is needed please let me know. Thanks in advance. Code:
Code:


Posted by admin (Graham Ellis), 8 July 2004
I guess you're using Tk?

Suggested scheme ...

a) when a request comes in, add it on to a global list.
b) In your main code (before you enter your main event handling loop), register an event to happen after one second.
c) When your 1 second event happens, have it
 1) Start the first process in your global list, if any
 2) Move your global list up if necessary
 3) Reset the event trigger

Not something I've done, but have a look at "event generate" which I suspect has the facilities you need.

Posted by ardikus (ardikus), 8 July 2004
Thanks a TON for your response, I finally got this thing figured out. Your suggestion was just what I needed. I used the FIFO queue suggested at this wiki site: http://wiki.tcl.tk/9552 and then drew my commands off of this queue in a main loop every one second. Once again thanks, this has been bugging me for days  

Posted by admin (Graham Ellis), 8 July 2004
Delighted to be of service ... and thanks for the onwards link too.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho