Some fixes for powerline.lib.threaded

Should fix #813 as well as other problems found when creating test suite.