Wait for signal

These commits introduce the waitForSignal function, which I'm using to test my sync code. I also did a bit of rewrite on existing test_preview.py code to use this function, plus fixed a bug in base.py.