2

Pressing Ctrl+C (or +Z or anything else) - does not terminate a haskell application (or happstack app) in windows command line (or power shell).

Currently I have to close the window, and then open a new command line/power-shell window, navigate to the app location and launch it again with runhaskell. Is there an easier way to make the app "auto reload" whenever code changes?

Or am I doing something wrong?

Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272
  • I'm guessing here but doesn't Ctrl-C generate exception that by default is handled by closing the app? If so, it'd only be a matter of readding such handler around Happstack's IO action that starts server. There's also Happstack.Server.SimpleHttp.waitForTermination :: IO (). – Marek Sieradzki Dec 30 '11 at 01:18
  • Sorry, but I'm completely new to hapstack - could you perhaps provide a more detailed example? Also could you post it as an answer (so I can accept it if applicable)? – Andriy Drozdyuk Dec 30 '11 at 08:28

1 Answers1

2

There is some issue with Ctrl-C and windows in general. I am not really clear on the details. Maybe someone who uses windows can come up with a better fix.

The easiest thing to do is to use forkIO and waitForTermination

do tid <- forkIO $ simpleHTTP nullConf yourApp
   waitForTermination
   killThread tid

waitForTermination just blocks until it receives the termination signal. On unix platforms, that is ^C. Under windows it is the letter 'e' (for exit). You might have to press the return key depending on buffering.

Under linux, you can use happstack-plugins/plugins-auto to automatically recompile and reload changes into the running server whenever the source files are saved. However, plugins-auto does not currently support Windows because it relies on the inotify library which is linux specific. There is some work underway to generalize the inotify support so that it can be used when available, and use a polling solution under windows.

To see an older demo of plugins-auto check out:

http://happstack.blogspot.com/2010/10/recompile-your-haskell-based-templates.html

stepcut
  • 1,502
  • 8
  • 10