Fix a bug where sleeping scripts could lose events (fix for Thonneve).