| Ticket UUID: | 9833d8dca1ec6cffd5fafd42cc30f055db195b45 | |||
| Title: | Can't change cron within a proc | |||
| Type: | Bug | Version: | 2.1 | |
| Submitter: | CrazyCat | Created on: | 2021-06-11 09:03:32 | |
| Subsystem: | cron | Assigned To: | hypnotoad | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Open | Last Modified: | 2026-11-16 00:06:15 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
A cron task cannot be modified within a procedure. % proc mycron {} { puts "done : [::cron::task info test]"; ::cron::every test 10 mycron}
% ::cron::every test 37 mycron
[10:35:53] done : object {} lastevent 1623400554001 lastrun 1623400554001 err 0 result {} running 1 coroutine {} scheduled 1623400591000 frequency 37000 command mycron
[10:36:31] done : object {} lastevent 1623400591641 lastrun 1623400591641 err 0 result {} running 1 coroutine {} scheduled 1623400628000 frequency 37000 command mycron
[10:37:07] done : object {} lastevent 1623400628002 lastrun 1623400628002 err 0 result {} running 1 coroutine {} scheduled 1623400665000 frequency 37000 command mycron
% ::cron::in test 3 mycron
[10:37:10] done : object {} lastevent 1623400631001 lastrun 1623400631001 err 0 result {} running 1 coroutine {} scheduled 1623400631000 frequency -1 command mycron
I had also try with ::cron::in and same result.
| |||
| User Comments: |
serhiy.storchaka added on 2026-11-16 00:06:15:
Proposed fix in branch cron-task-reschedule: the task command ran inside dict with, which restored the old settings afterwards. It now runs outside, and a one-shot task that reschedules itself is kept. Tests cron-1.9 and cron-1.10. hypnotoad (claiming to be Sean Woods) added on 2024-01-09 12:42:30: The problem is that we are running inside a "dict with" (line 457) when they process is executed. The loop will rewrite the state back into the dict, unwriting all of the modifications. The quick and dirty would be to simply invoke an "after 0 [list ::cron::task set task frequency 10]", which will fire off an event outside of the dict. I think for the future I need to modify that section, because it opens us up to important variables being swapped, keeps a context state in play, and the "uplevel #0" pretty much ensures that no local variable is going to be modified anyway. aku added on 2022-05-05 12:53:38: My quick hypothesis was that the internal setup of the next scheduled event overrides the change done by the called command. That would have been easy to see for a simple implementation using `after`. The cron implementation is unfortunately not simple. While it uses `after` for basic timing, there also coroutines involved. My quick look was unable to discern how things are done. I still suspect some part of the cron internals restoring the old state. Might be interesting to see what `task info` reports after the `every` inside of the cron command. A side question which occurred: What is the desired use case of this ? aku added on 2022-03-30 09:31:39: @hypnotoad - Could you have a look at this ? | |||
Home
Blog
Docs
Downloads
Tickets
Timeline
Branches
Tags
Wiki