One of the things from tcl I find nice is the event loop. There are
several things I want to do every so often and it is very easy to put
that in a single script. And when I want to add another that is a
cinch.
But I also open a process that generates every minute a line of
output. This I have in another script. But it would be nicer if
everything is in the same script.
Is there a way that just like after executes a proc after a certain
amount of time, a proc can be called when there is another line of
output, so the other procs still can be executed when it is their
time?
* Harald Oehlmann <wort...@yahoo.de>
| Sketch from brain:
| set h [open |...]
| fconfigure $h -blocking 0 -buffering line
| fileevent readable $h readproc
| proc readproc {} {
Better yet w/o globals and hardcoded file descriptors:
fileevent readable $h [list readproc $h]
proc readproc {fd} {
read $fd
eof $fd
...
}
R'
On Monday, November 22, 2021 at 7:58:43 AM UTC-8, Ralf Fassel wrote:
* Harald Oehlmann <wort...@yahoo.de>
| Sketch from brain:
| set h [open |...]
| fconfigure $h -blocking 0 -buffering line
| fileevent readable $h readproc
| proc readproc {} {
Better yet w/o globals and hardcoded file descriptors:
fileevent readable $h [list readproc $h]
proc readproc {fd} {
read $fd
eof $fd
...
}
R'
Don't need any proc either:
coroutine background-reporter#1 apply {{cmd args} {
set h [open "| $cmd $args"]
fconfigure $h -blocking 0 -buffering line
fileevent readable $h [info coroutine]
while { ! [eof $h]} {
yield
read $h line
puts $line
}
if {[catch {close $h} err]} {
puts stderr $err
}
}} external-reporter-generator
On Monday, November 22, 2021 at 7:58:43 AM UTC-8, Ralf Fassel wrote:
* Harald Oehlmann <wort...@yahoo.de>
| Sketch from brain:
| set h [open |...]
| fconfigure $h -blocking 0 -buffering line
| fileevent readable $h readproc
| proc readproc {} {
Better yet w/o globals and hardcoded file descriptors:
fileevent readable $h [list readproc $h]
proc readproc {fd} {
read $fd
eof $fd
...
}
R'
Don't need any proc either:
coroutine background-reporter#1 apply {{cmd args} {
set h [open "| $cmd $args"]
fconfigure $h -blocking 0 -buffering line
fileevent readable $h [info coroutine]
while { ! [eof $h]} {
yield
read $h line
puts $line
}
if {[catch {close $h} err]} {
puts stderr $err
}
}} external-reporter-generator
briang <bgriffin...@gmail.com> writes:
On Monday, November 22, 2021 at 7:58:43 AM UTC-8, Ralf Fassel wrote:
* Harald Oehlmann <wort...@yahoo.de>
| Sketch from brain:
| set h [open |...]
| fconfigure $h -blocking 0 -buffering line
| fileevent readable $h readproc
| proc readproc {} {
Better yet w/o globals and hardcoded file descriptors:
fileevent readable $h [list readproc $h]
proc readproc {fd} {
read $fd
eof $fd
...
}
R'
Don't need any proc either:
coroutine background-reporter#1 apply {{cmd args} {It looks quit interesting, but I understand it only partly. Are there
set h [open "| $cmd $args"]
fconfigure $h -blocking 0 -buffering line
fileevent readable $h [info coroutine]
while { ! [eof $h]} {
yield
read $h line
puts $line
}
if {[catch {close $h} err]} {
puts stderr $err
}
}} external-reporter-generator
any good resources to learn about this?
What needs external-reporter-generator to be?
Do I see it correctly that I have to call background-reporter#1 with
the needed parameters and then do a 'vwait forever'?
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
But I also open a process that generates every minute a line of
output. This I have in another script. But it would be nicer if
everything is in the same script.
On Tuesday, November 23, 2021 at 7:44:06 AM UTC-8, Cecil Westerhof wrote:
briang <bgriffin...@gmail.com> writes:
On Monday, November 22, 2021 at 7:58:43 AM UTC-8, Ralf Fassel wrote:It looks quit interesting, but I understand it only partly. Are there
* Harald Oehlmann <wort...@yahoo.de>
| Sketch from brain:
| set h [open |...]
| fconfigure $h -blocking 0 -buffering line
| fileevent readable $h readproc
| proc readproc {} {
Better yet w/o globals and hardcoded file descriptors:
fileevent readable $h [list readproc $h]
proc readproc {fd} {
read $fd
eof $fd
...
}
R'
Don't need any proc either:
coroutine background-reporter#1 apply {{cmd args} {
set h [open "| $cmd $args"]
fconfigure $h -blocking 0 -buffering line
fileevent readable $h [info coroutine]
while { ! [eof $h]} {
yield
read $h line
puts $line
}
if {[catch {close $h} err]} {
puts stderr $err
}
}} external-reporter-generator
any good resources to learn about this?
Great questions Cecil!
There have been several presentations at the US Tcl and Euro Tcl
conferences over the years. You should be able to find the papers/presentations in the proceedings online. I cannot immediately
recall the titles. I learned how to use them through practice, i.e.,
applying them wherever and whenever I could. Through trial and error I
gained a lot of knowledge. :)
What needs external-reporter-generator to be?
This is a place holder for whatever external program/process is
generating the periodic output. The coroutine will launch the program
and then consume that program's output until the EOF, after which it
will clean up and terminate itself (the coroutine.)
Do I see it correctly that I have to call background-reporter#1 with
the needed parameters and then do a 'vwait forever'?
The initial [coroutine] call will evaluate the function and return when
the function executes the first [yield] or [return] command. After that,
the assumption is that there is an overall event wait loop running. This
is the base assumption for all Tk programs, for example. Non-Tk tcl
programs can operate that way as well. It is best if there is only 1
[vwait forever], instead of having point [vwait ...] sprinkled
throughout the code.
briang <bgriffin...@gmail.com> writes:
On Tuesday, November 23, 2021 at 7:44:06 AM UTC-8, Cecil Westerhof wrote:
briang <bgriffin...@gmail.com> writes:
On Monday, November 22, 2021 at 7:58:43 AM UTC-8, Ralf Fassel wrote:It looks quit interesting, but I understand it only partly. Are there
* Harald Oehlmann <wort...@yahoo.de>
| Sketch from brain:
| set h [open |...]
| fconfigure $h -blocking 0 -buffering line
| fileevent readable $h readproc
| proc readproc {} {
Better yet w/o globals and hardcoded file descriptors:
fileevent readable $h [list readproc $h]
proc readproc {fd} {
read $fd
eof $fd
...
}
R'
Don't need any proc either:
coroutine background-reporter#1 apply {{cmd args} {
set h [open "| $cmd $args"]
fconfigure $h -blocking 0 -buffering line
fileevent readable $h [info coroutine]
while { ! [eof $h]} {
yield
read $h line
puts $line
}
if {[catch {close $h} err]} {
puts stderr $err
}
}} external-reporter-generator
any good resources to learn about this?
Great questions Cecil!
There have been several presentations at the US Tcl and Euro Tcl conferences over the years. You should be able to find the papers/presentations in the proceedings online. I cannot immediatelyI did find a few YouTube Tcl conferences videos about coroutines, but
recall the titles. I learned how to use them through practice, i.e., applying them wherever and whenever I could. Through trial and error I gained a lot of knowledge. :)
nothing that helped me. :'-(
When I have it working I probably should post something.
What needs external-reporter-generator to be?
This is a place holder for whatever external program/process isI probably do misunderstand something, but is the process behind
generating the periodic output. The coroutine will launch the program
and then consume that program's output until the EOF, after which it
will clean up and terminate itself (the coroutine.)
filepointer h not generating the output?
And here the placeholder (at the end of the page) is not used: https://wiki.tcl-lang.org/page/Coronet
Do I see it correctly that I have to call background-reporter#1 with
the needed parameters and then do a 'vwait forever'?
The initial [coroutine] call will evaluate the function and return whenI use a (single) vwait in a systemd process where I want to log
the function executes the first [yield] or [return] command. After that, the assumption is that there is an overall event wait loop running. This
is the base assumption for all Tk programs, for example. Non-Tk tcl programs can operate that way as well. It is best if there is only 1
[vwait forever], instead of having point [vwait ...] sprinkled
throughout the code.
several different things. That part work great. Just want to integrate
the consume of a process with it.
I did find a few YouTube Tcl conferences videos about coroutines, but
nothing that helped me. :'-(
I did find a few YouTube Tcl conferences videos about coroutines, butIt looks quit interesting, but I understand it only partly. Are there
any good resources to learn about this?
Great questions Cecil!
There have been several presentations at the US Tcl and Euro Tcl
conferences over the years. You should be able to find the
papers/presentations in the proceedings online. I cannot immediately
recall the titles. I learned how to use them through practice, i.e.,
applying them wherever and whenever I could. Through trial and error I
gained a lot of knowledge. :)
nothing that helped me. :'-(
This is what I found so far. Note: the term "coro" is often used in discussions, so I used that in my search.
http://www.tclcommunityassociation.org/wub/proceedings/Proceedings-2008/proceedings/nre/coroSlides.pdf
http://www.tclcommunityassociation.org/wub/proceedings/Proceedings-2008/proceedings/nre/tailSlides.pdf
http://www.tclcommunityassociation.org/wub/proceedings/Proceedings-2011/SeanWood/Agent-Based-Modeling-with-Coroutines.pdf
http://www.tclcommunityassociation.org/wub/proceedings/Proceedings-2012/SeanWoods/Lifecycle-of-Objects.pdf
https://ssl.webpack.de/www.eurotcl.tcl3d.org/presentations/EuroTcl2019-Macleod-ExpectCoroutines.pdf
https://youtu.be/WGYl0LiPv80 https://www.magicsplat.com/blog/coro-iterate/index.html
https://wiki.tcl-lang.org/page/Tcl+Conferences
When I have it working I probably should post something.
I probably do misunderstand something, but is the process behindWhat needs external-reporter-generator to be?
This is a place holder for whatever external program/process is
generating the periodic output. The coroutine will launch the program
and then consume that program's output until the EOF, after which it
will clean up and terminate itself (the coroutine.)
filepointer h not generating the output?
Yes, that is correct. The [open] call in prior examples used "|...". I
simply named the "..." as "$cmd $args", and the example call passes the argument "external-reporter-generator" as the cmd argument.
And here the placeholder (at the end of the page) is not used:
https://wiki.tcl-lang.org/page/Coronet
In the Coronet example, the apply function has no argument: apply {{} {... In my example, the apply has 2 arguments: apply {{cmd args} {...
I use a (single) vwait in a systemd process where I want to logDo I see it correctly that I have to call background-reporter#1 with
the needed parameters and then do a 'vwait forever'?
The initial [coroutine] call will evaluate the function and return when
the function executes the first [yield] or [return] command. After that, >> > the assumption is that there is an overall event wait loop running. This >> > is the base assumption for all Tk programs, for example. Non-Tk tcl
programs can operate that way as well. It is best if there is only 1
[vwait forever], instead of having point [vwait ...] sprinkled
throughout the code.
several different things. That part work great. Just want to integrate
the consume of a process with it.
Well, without actual code, it's hard for me to understand the
intended behavior and the flow.
One of the things from tcl I find nice is the event loop. There are
several things I want to do every so often and it is very easy to put
that in a single script. And when I want to add another that is a
cinch.
But I also open a process that generates every minute a line of
output. This I have in another script. But it would be nicer if
everything is in the same script.
Is there a way that just like after executes a proc after a certain
amount of time, a proc can be called when there is another line of
output, so the other procs still can be executed when it is their
time?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 285 |
Nodes: | 16 (2 / 14) |
Uptime: | 65:05:07 |
Calls: | 6,488 |
Calls today: | 1 |
Files: | 12,096 |
Messages: | 5,274,919 |