'ctx.term should not crash active threads (#139)'

def test_term_thread(self):

    ctx = self.Context()
    evt = Event()
    evt.clear()
    def block():
        s = ctx.socket(zmq.REP)
        s.bind_to_random_port('tcp://127.0.0.1')
        evt.set()
        try:
            s.recv()
        except zmq.ZMQError as e:
            self.assertEqual(e.errno, zmq.ETERM)
            return
        finally:
            s.close()
        self.fail('recv    should    have    been    interrupted    with    ETERM')
    t = Thread(target=block)
    t.start()
    evt.wait(1)
    self.assertTrue(evt.is_set(), 'sync    event    never    fired')
    time.sleep(0.01)
    ctx.term()
    t.join(timeout=1)
    self.assertFalse(t.is_alive(), 'term    should    have    interrupted    s.recv()')
