PasteRack.org
Paste # 64770
2018-12-06 13:06:02

Fork as a new paste.

Paste viewed 130 times.


Embed:

Graceful web server restarts

  1. #lang racket/base
  2.  
  3. (require
  4.  web-server/http/response
  5.  web-server/http/response-structs
  6.  web-server/web-server)
  7.  
  8. (define (hello-world conn req)
  9.   (define r
  10.     (response/output
  11.      (λ (out)
  12.        (write-bytes #"begin\n" out)
  13.        (flush-output out)
  14.        (sleep 10)
  15.        (write-bytes #"end\n" out))))
  16.   (output-response conn r))
  17.  
  18. (define stop (serve #:dispatch hello-world #:port 8000))
  19. (with-handlers ([exn:break? (λ (e)
  20.                               (printf "stopping...~n")
  21.                               (stop))])
  22.   (sync/enable-break never-evt))

=>

tcp-listen: network access denied: '(#f 8000 server)

  context...:

   .../more-scheme.rkt:261:28

   /home/pasterack/racket68/share/pkgs/compatibility-lib/mzlib/kw.rkt:468:41: run-server

with-limit: out of time