Example #1
0
 def __init__(self, port, RequestHandlerClass):
     threading.Thread.__init__(self)
     self._RequestHandlerClass = RequestHandlerClass
     self._stop = False
     self._port = port
     self._server_address = ('127.0.0.1', self._port)
     self.ready = threading.Event()
Example #2
0
 def __init__(self, operation, node, element, cfd, inputdata, cfg, output):
     self.sensormap = {}
     self.invmap = {}
     self.output = output
     self.sensorcategory = None
     self.broken = False
     self.error = None
     eventlet.sleep(0)
     self.cfg = cfd[node]
     self.loggedin = False
     self.node = node
     self.element = element
     self.op = operation
     connparams = get_conn_params(node, self.cfg)
     self.ipmicmd = None
     self.inputdata = inputdata
     tenant = cfg.tenant
     self._logevt = None
     if ((node, tenant) not in persistent_ipmicmds or
             not persistent_ipmicmds[(node, tenant)].ipmi_session.logged):
         self._logevt = threading.Event()
         try:
             persistent_ipmicmds[(node, tenant)].close_confluent()
         except KeyError:  # was no previous session
             pass
         try:
             persistent_ipmicmds[(node, tenant)] = IpmiCommandWrapper(
                 node, cfg, bmc=connparams['bmc'],
                 userid=connparams['username'],
                 password=connparams['passphrase'], kg=connparams['kg'],
                 port=connparams['port'], onlogon=self.logged)
         except socket.gaierror as ge:
             if ge[0] == -2:
                 raise exc.TargetEndpointUnreachable(ge[1])
     self.ipmicmd = persistent_ipmicmds[(node, tenant)]
Example #3
0
    def _setUp(self):
        self.server_ready = threading.Event()
        self.client_ready = threading.Event()
        self.done = threading.Event()
        self.queue = Queue.Queue(1)

        # Do some munging to start the client test.
        methodname = self.id()
        i = methodname.rfind('.')
        methodname = methodname[i + 1:]
        test_method = getattr(self, '_' + methodname)
        self.client_thread = thread.start_new_thread(self.clientRun,
                                                     (test_method, ))

        self.__setUp()
        if not self.server_ready.isSet():
            self.server_ready.set()
        self.client_ready.wait()
Example #4
0
def test_rude_shutdown__write():
    if test_support.verbose:
        print "test_rude_shutdown__variant ..."

    from eventlet.green import threading

    # Some random port to connect to.
    PORT = [9934]

    listener_ready = threading.Event()
    listener_gone = threading.Event()

    # `listener` runs in a thread.  It opens a socket listening on PORT, and
    # sits in an accept() until the main thread connects.  Then it rudely
    # closes the socket, and sets Event `listener_gone` to let the main thread
    # know the socket is gone.
    def listener():
        s = socket.socket()
        PORT[0] = test_support.bind_port(s, '', PORT[0])
        s.listen(5)
        listener_ready.set()
        s.accept()
        s = None  # reclaim the socket object, which also closes it
        listener_gone.set()

    def connector():
        listener_ready.wait()
        s = socket.socket()
        s.connect(('localhost', PORT[0]))
        listener_gone.wait()
        try:
            ssl_sock = socket.ssl(s)
            ssl_sock.write("hello")
        except socket.sslerror:
            pass
        else:
            raise test_support.TestFailed(
                'connecting to closed SSL socket should have failed')

    t = threading.Thread(target=listener)
    t.start()
    connector()
    t.join()
    def test_no_double_start(self):
        wait_ev = greenthreading.Event()

        def _run_forever_until_set():
            if wait_ev.is_set():
                raise loopingcall.LoopingCallDone(True)

        timer = loopingcall.FixedIntervalLoopingCall(_run_forever_until_set)
        timer.start(interval=0.01)

        self.assertRaises(RuntimeError, timer.start, interval=0.01)

        wait_ev.set()
        timer.wait()
    def test_no_double_start(self):
        wait_ev = greenthreading.Event()

        def _run_forever_until_set():
            if wait_ev.is_set():
                raise loopingcall.LoopingCallDone(True)
            else:
                return 0.01

        timer = loopingcall.DynamicLoopingCall(_run_forever_until_set)
        timer.start()

        self.assertRaises(RuntimeError, timer.start)

        wait_ev.set()
        timer.wait()
Example #7
0
 def event_object(*args, **kwargs):
     return greenthreading.Event(*args, **kwargs)
Example #8
0
 def make_event():
     return threading.Event()
Example #9
0
 def __init__(self):
     self.event = greenthreading.Event()
Example #10
0
 def __init__(self, pending):
     self.event = greenthreading.Event()
     self.lock = greenthreading.Lock()
     self.pending = pending
Example #11
0
 def event_object(self):
     return green_threading.Event()
Example #12
0
    def test_PyThreadState_SetAsyncExc(self):
        try:
            import ctypes
        except ImportError:
            if verbose:
                print "test_PyThreadState_SetAsyncExc can't import ctypes"
            return  # can't do anything

        set_async_exc = ctypes.pythonapi.PyThreadState_SetAsyncExc

        class AsyncExc(Exception):
            pass

        exception = ctypes.py_object(AsyncExc)

        # `worker_started` is set by the thread when it's inside a try/except
        # block waiting to catch the asynchronously set AsyncExc exception.
        # `worker_saw_exception` is set by the thread upon catching that
        # exception.
        worker_started = threading.Event()
        worker_saw_exception = threading.Event()

        class Worker(threading.Thread):
            def run(self):
                self.id = thread.get_ident()
                self.finished = False

                try:
                    while True:
                        worker_started.set()
                        time.sleep(0.1)
                except AsyncExc:
                    self.finished = True
                    worker_saw_exception.set()

        t = Worker()
        t.setDaemon(True)  # so if this fails, we don't hang Python at shutdown
        t.start()
        if verbose:
            print "    started worker thread"

        # Try a thread id that doesn't make sense.
        if verbose:
            print "    trying nonsensical thread id"
        result = set_async_exc(ctypes.c_long(-1), exception)
        self.assertEqual(result, 0)  # no thread states modified

        # Now raise an exception in the worker thread.
        if verbose:
            print "    waiting for worker thread to get started"
        worker_started.wait()
        if verbose:
            print "    verifying worker hasn't exited"
        self.assert_(not t.finished)
        #         if verbose:
        #             print "    attempting to raise asynch exception in worker"
        #         result = set_async_exc(ctypes.c_long(t.id), exception)
        #         self.assertEqual(result, 1) # one thread state modified
        #         if verbose:
        #             print "    waiting for worker to say it caught the exception"
        #         worker_saw_exception.wait(timeout=10)
        #         self.assert_(t.finished)
        if verbose:
            print "    all OK(2 disabled) -- joining worker"
        if t.finished:
            t.join()