Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sandbox GUI event handling #4272

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkgs/racket-doc/scribblings/reference/sandbox.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,16 @@ sandbox. The default value of the parameter is @racket[#t].
Various aspects of the library change when the GUI library is
available, such as using a new eventspace for each evaluator.}

@defboolparam[sandbox-gui-yield? yield? #:value #f]{

Determines whether the evaluator thread handles GUI events between sandbox
interactions. If the value is @racket[#f], then any GUI windows created in the
evaluator's initial eventspace will be unresponsive unless the evaluator is
instructed to handle events by calling @racket[yield] or @racket[sleep/yield].

The default value is @racket[#f] for backwards compatibility.

@history[#:added "8.5.0.8"]}

@defparam[sandbox-override-collection-paths paths (listof path-string?)]{

Expand Down
24 changes: 0 additions & 24 deletions pkgs/sandbox-lib/README.md

This file was deleted.

12 changes: 9 additions & 3 deletions pkgs/sandbox-lib/racket/sandbox.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

(provide gui?
sandbox-gui-available
sandbox-gui-yield?
sandbox-init-hook
sandbox-reader
sandbox-input
Expand Down Expand Up @@ -75,6 +76,10 @@
[(mz/mr mzval mrsym)
(if (sandbox-gui-available) (gui-dynamic-require 'mrsym) mzval)]))

;; When this parameter is #t, the evaluator thread (an eventspace handler
;; thread) handles events while waiting for things to evaluate.
(define sandbox-gui-yield? (make-parameter #f (lambda (v) (and v #t))))

;; Configuration ------------------------------------------------------------

(define sandbox-init-hook (make-parameter void))
Expand Down Expand Up @@ -888,7 +893,7 @@
(when raise? (raise terminated?)))
(define (user-break)
(when user-thread (break-thread user-thread)))
(define (user-process)
(define (user-process sync/yield)
(define break-paramz (current-break-parameterization))
(parameterize-break
#f ;; disable breaks during administrative work
Expand All @@ -915,7 +920,7 @@
;; finally wait for interaction expressions
(define n 0)
(let loop ()
(define expr (channel-get input-ch))
(define expr (sync/yield input-ch))
(when (eof-object? expr)
(terminated! 'eof) (channel-put result-ch expr) (user-kill))
(with-handlers ([void (lambda (exn)
Expand Down Expand Up @@ -1204,7 +1209,8 @@
(lambda (ignored)
((mz/mr void eventspace-handler-thread) (current-eventspace)))
values))
(define t (bg-run->thread (run-in-bg user-process)))
(define sync/yield (if (sandbox-gui-yield?) (mz/mr sync yield) sync))
(define t (bg-run->thread (run-in-bg (lambda () (user-process sync/yield)))))
(set! user-done-evt (handle-evt t (lambda (_) (terminate+kill! #t #t))))
(set! user-thread t)))
(define r (get-user-result))
Expand Down