| Ticket UUID: | cd4fe2d0471a7be1524314421eea45243b0e1738 | |||
| Title: | coroutine::auto causes auto_load to fail | |||
| Type: | Bug | Version: | 1.1.3 of coroutine::auto | |
| Submitter: | [email protected] | Created on: | 2017-08-16 23:15:29 | |
| Subsystem: | (unused) | Assigned To: | aku | |
| Priority: | 7 High | Severity: | Severe | |
| Status: | Open | Last Modified: | 2017-08-30 01:07:28 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
coroutine::auto, among other things redefines "global". If, while in a coroutine an unknown command is encountered the auto_load mechanism is invoked to load the command. This fails because auto_load and friends depend on the globals auto_index and auto_path (at least). Here is a simple test routine that fails:
!/bin/env tclsh
#
# try clock format from inside a corouting
#
#package require Tk
package require coroutine::auto
package require coroutine
variable clockFormat "On %D at %H:%M:%S"
proc t1 {} {
variable clockFormat
set tm [clock format [clock seconds] -format $clockFormat]
puts "$tm"
}
coroutine cor_foo t1
t1
# end of test routine
Here is a workaround for this problem:
if {[catch {info body global}] == 0} {
# the real 'global' is not a procedure
set ns ::coroutine::auto
rename ::global ${ns}::wrap_global
rename ${ns}::core_global ::global
}
A comment on what I think ought to be the real fix:
First, I think "global" should not be renamed or replaced. What is wanted/needed is a coroutine local global which the current code puts at 'uplevel #1' This seems fine except for the notion of calling such variables 'global's. This is a new sort of global and, as such, ought to have a new name, for example corglobal" corglobal, should throw and error if it is called outside of a coroutine.
An issue I don't see resolved is how to refer to a corglobal form outside of the coroutine, such as, for example, a textvariable, or a command script to be executed when a button is pressed.
| |||
| User Comments: |
[email protected] (claiming to be tomturkey) added on 2017-08-30 01:07:28:
I am not sure I would agree on the "not really 'auto'". I found that
the package with out the 'global' was very useful. (I am working with
vwait and after to do waits that time out and refer to the global for
vwait as ::foo)
I did not mention the additional issue around 'global' of a global
being referenced as "::foo" as well as "global foo".
On the issue of referring to a coroutine variable from outside of the coro I think what may do the trick is to lean on "namespace", possibly such that a coroutines globals (corglobals) are in the namespace that seems to be created for each command already. One might then write:
proc ::coroutine::util::global {args} {
foreach corglobal $args {
variable [info coroutine]::$corglobal
}
}
This would create a variable that can be accessed from anywhere including as a textvariable. And if invoked while not in a coroutine, creates a simple global.
I realize this is not "auto" but it is clear to me that corglobals are NOT the same thing as our other globals. I think this also solves the problem of referring a coroutine global from the true global space.
This is, of course, NOT part of "auto" but of coroutine. Also I would suggest renaming "::coroutine::util::global" to "coroutine::util::corovariable" just to make it clear that this is a coroutine variable.
aku added on 2017-08-28 18:34:36: The intent behind writing `coro::auto` was to allow pre-existing functionality/procedures to be run either normally, or within a coro context, without having to rewrite them. The intent behind the particular rewrite of `global` was to allow multiple coros based on the same procedure without having them interfere in each other's state. Given the trouble with that in regular code, like `clock`, I would say that this experiment has failed. As such I would rather disable/deprecate/remove `coro::auto` entirely, i.e. give up on automatic support for code in both regular and coro contexts, and be explicit when writing functionality about the context it should be in. On the other hand, some of the ideas apparently do work (i.e. channel IO support). Given that a middle position would be to keep the support which works, and drop the other things, i.e. `global`, or rework them to not interfere with the standard builtin. That actually matches the proposed `real fix` in the description of the ticket. In that case the package is however not really `auto` anymore. Partially yes, for IO, and partially not, for scoping and variables. Do we have a better name for the package modified this way ? On the issue of refering to a cor-global outside of the coro ... AFAIK that is not possible at all. | |||
Home
Blog
Docs
Downloads
Tickets
Timeline
Branches
Tags
Wiki