racket / web-server

Other
90 stars 47 forks source link

Printing is silenced when starting server from terminal #136

Closed maxime-pigeon closed 4 months ago

maxime-pigeon commented 4 months ago

I tried executing this program using racket on macOS from iTerm:

#lang racket/base
(require web-server/servlet-env web-server/http)
(serve/servlet (λ (req) (print req) (response/xexpr `(html))))

It works in DrRacket, but not in the terminal. The output is printed only once the server is closed.

sorawee commented 4 months ago

This seems to be due to buffering, and not really a web server issue. Calling (flush-output) to forcefully flush the output port will fix your problem.

maxime-pigeon commented 4 months ago

I see. Thanks for the response! For future reference (if anyone else encounters this ‘issue’): https://docs.racket-lang.org/reference/port-buffers.html#(part._port-buffers. Also, writeln, println and displayln flushes the buffer.