Example #1
0
 def disconnected(emitter):
     log.info("Exited!?")
     try:
         gevent.shutdown()
     except AssertionError:
         # Shutting down is only possible from MAIN greenlet
         pass
Example #2
0
    def wait_for_complete(self):
        '''等待所有线程完成'''

        while len(self.threads):
            thread = self.threads.pop()
            thread.join()
        gevent.shutdown()
Example #3
0
 def disconnected(emitter):
     log.info("Exited!?")
     try:
         gevent.shutdown()
     except AssertionError:
         # Shutting down is only possible from MAIN greenlet
         pass
Example #4
0
	def wait_for_complete(self):
	    '''等待所有线程完成'''

	    while len(self.threads):
	        thread = self.threads.pop()
	        thread.join()
	    gevent.shutdown()
Example #5
0
    def disconnect(self):
        for nick, data in self.jabber_users.items():
            self.jjc.part_room(data.room_jid, data.jid)

        for jid, data in self.irc_users.items():
            self.jic.quit_nick(data.irc_nick)

        self.jjc.disconnect()
        self.jic.disconnect()

        [g.kill() for g in self.greenlets]
        gevent.shutdown()
Example #6
0
def run(args):
    # Note that gevent monkey patching must be done before importing the
    # `threading` module, see http://stackoverflow.com/questions/8774958/.
    if args.gevent:
        import gevent
        import gevent.monkey
        import gevent.wsgi
        import gevent_psycopg2
        gevent.monkey.patch_all()
        gevent_psycopg2.monkey_patch()
    import threading
    import openerp
    import openerp.cli.server
    import openerp.service.wsgi_server
    import openerp.tools.config
    config = openerp.tools.config

    os.environ["TZ"] = "UTC"
    common.set_addons(args)

    openerp.multi_process = True
    common.setproctitle('openerp-web')

    openerp.cli.server.check_root_user()
    openerp.netsvc.init_logger()
    #openerp.cli.server.report_configuration()
    openerp.cli.server.configure_babel_localedata_path()

    target = openerp.service.wsgi_server.serve
    if not args.gevent:
        openerp.evented = False
        openerp.cli.server.setup_signal_handlers(openerp.cli.server.signal_handler)
        # TODO openerp.multi_process with a multi-threaded process probably
        # doesn't work very well (e.g. waiting for all threads to complete
        # before killing the process is not implemented).
        arg = (args.interface, int(args.port), args.threaded)
        threading.Thread(target=target, args=arg).start()
        openerp.cli.server.quit_on_signals()
    else:
        openerp.evented = True

        app = openerp.service.wsgi_server.application
        server = gevent.wsgi.WSGIServer((args.interface, int(args.port)), app)
        setup_signal_handlers(mk_signal_handler(server))
        try:
            server.serve_forever()
        except KeyboardInterrupt:
            try:
                server.stop()
                gevent.shutdown()
            except KeyboardInterrupt:
                sys.stderr.write("Forced shutdown.\n")
                gevent.shutdown()
Example #7
0
def stop_service():
    """ Initiate the shutdown of the WSGI server.

    The server is supposed to have been started by start_server() above.
    """
    if httpd:
        if not openerp.evented:
            httpd.shutdown()
            close_socket(httpd.socket)
        else:
            import gevent
            httpd.stop()
            gevent.shutdown()
Example #8
0
 def shutdown(self):
     if not self.has_shutdown:
         # shutdown all greenlets and clean up
         gevent.killall(self.greenlets)
         self.qh.shutdown()
         try:
             self.gm.shutdown()
         except KeyboardInterrupt:
             pass
         self.dm.shutdown()
         gevent.shutdown()
         self.has_shutdown = True
         logger.info('Server exit nicely.')
Example #9
0
 def shutdown(self):
     if not self.has_shutdown:
         # shutdown all greenlets and clean up
         gevent.killall(self.greenlets)
         self.qh.shutdown()
         try:
             self.gm.shutdown()
         except KeyboardInterrupt:
             pass
         self.dm.shutdown()
         gevent.shutdown()
         self.has_shutdown = True
         logger.info('Server exit nicely.')
Example #10
0
def stop_service():
    """ Initiate the shutdown of the WSGI server.

    The server is supposed to have been started by start_server() above.
    """
    if httpd:
        if not openerp.evented:
            httpd.shutdown()
            close_socket(httpd.socket)
        else:
            import gevent

            httpd.stop()
            gevent.shutdown()
Example #11
0
def run_ctl(args, stdin=''):
    cmd = '%s -m circus.circusctl' % sys.executable
    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    if stdin:
        proc.stdin.write(stdin)

    stderr = proc.stderr.read()
    stdout = proc.stdout.read()
    proc.wait()
    try:
        import gevent
        gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
Example #12
0
def run_ctl(args, stdin=''):
    cmd = '%s -m circus.circusctl' % sys.executable
    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    if stdin:
        proc.stdin.write(stdin)

    stderr = proc.stderr.read()
    stdout = proc.stdout.read()
    proc.wait()
    try:
        import gevent
        gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
Example #13
0
def run_ctl(args, queue=None, stdin=''):
    cmd = '%s -m circus.circusctl' % sys.executable
    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE if stdin else None,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate(b(stdin) if stdin else None)
    stdout = s(stdout)
    stderr = s(stderr)
    if queue:
        queue.put(stderr)
        queue.put(stdout)
    try:
        import gevent
        if hasattr(gevent, 'shutdown'):
            gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
Example #14
0
def run_ctl(args, queue=None, stdin=''):
    cmd = '%s -m circus.circusctl' % sys.executable
    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE if stdin else None,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate(b(stdin) if stdin else None)
    stdout = s(stdout)
    stderr = s(stderr)
    if queue:
        queue.put(stderr)
        queue.put(stdout)
    try:
        import gevent
        if hasattr(gevent, 'shutdown'):
            gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
Example #15
0
def google_training_docs(query, num_docs):
    print 'Running web search,', query, num_docs
    urls = web_query(query, num_docs)    
    print 'Web search returned', len(urls), 'results'    

    pages = []    
    try:
        jobs = [gevent.spawn(download_doc, urlset) for urlset in partition_list(urls,5)]
        gevent.joinall(jobs)
    
        for job in jobs:
            pages += job.value
    
    except Exception as inst:
        print inst
    finally:
        gevent.shutdown()
        
    return pages
Example #16
0
def run_ctl(args, queue=None, stdin='', endpoint=DEFAULT_ENDPOINT_DEALER):
    cmd = '%s -m circus.circusctl' % PYTHON
    if '--endpoint' not in args:
        args = '--endpoint %s ' % endpoint + args

    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE if stdin else None,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate(b(stdin) if stdin else None)
    stdout = s(stdout)
    stderr = s(stderr)
    if queue:
        queue.put(stderr)
        queue.put(stdout)
    try:
        import gevent
        if hasattr(gevent, 'shutdown'):
            gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
Example #17
0
def run_ctl(args, queue=None, stdin='', endpoint=DEFAULT_ENDPOINT_DEALER):
    cmd = '%s -m circus.circusctl' % PYTHON
    if '--endpoint' not in args:
        args = '--endpoint %s ' % endpoint + args

    proc = subprocess.Popen(cmd.split() + shlex.split(args),
                            stdin=subprocess.PIPE if stdin else None,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate(b(stdin) if stdin else None)
    stdout = s(stdout)
    stderr = s(stderr)
    if queue:
        queue.put(stderr)
        queue.put(stdout)
    try:
        import gevent
        if hasattr(gevent, 'shutdown'):
            gevent.shutdown()
    except ImportError:
        pass
    return stdout, stderr
Example #18
0
    def startwork():
        co_routines = []
        co_routines_status = 1
        for iNum in range(config.THREAD_NUM):
            worker = AlsWorker(config, log, iNum,view_name_list)
            work = gevent.spawn(worker.handle_tasks)
            co_routines.append(work)
        list_ippath = get_handlefilepath(config)
        for strippath in list_ippath:
            put_querywork(strippath)

        while 1:
            if tasks_workqueue.empty():
                co_statussem.acquire()
                co_routines_status = 0
                co_statussem.release()
                break
            if is_sigint_up:
                gevent.shutdown()
                break
            gevent.sleep(10)
        gevent.joinall(co_routines)
        out_result()  
Example #19
0
 def disconnected(emitter):
     try:
         gevent.shutdown()
     except AssertionError:
         pass
Example #20
0
def cleanup():
    fs.shutdown()
    zmq_context.term()
    gevent.shutdown()
Example #21
0
#! /usr/bin/evn python
#--encoding:utf-8--

import gevent
import signal

def run_forever():
    gevent.sleep(1000)

if __name__ == '__main__':
    gevent.signal(signal.SIGQUIT, gevent.shutdown())
    thread = gevent.spawn(run_forever)
    thread.join()
Example #22
0
def main():
    server = WSGIServer(("0.0.0.0", 5000), app)
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        gevent.shutdown()
Example #23
0
            while not tasks.empty():
                task = tasks.get()
                data = cipher.decrypt(task[:16]) + cipher.decrypt(task[16:])
                self.lastPacket = EmotivPacket(data, self.sensors)
                self.packets.put_nowait(self.lastPacket)
                self.packetsProcessed += 1
                gevent.sleep(0)
            gevent.sleep(0)

    def dequeue(self):
        try:
            return self.packets.get()
        except Exception, e:
            print e

    def close(self):
        if windows:
            self.device.close()
        else:
            self._goOn = False
            self.hidraw.close()


if __name__ == "__main__":
    try:
        a = Emotiv()
        a.setup()
    except KeyboardInterrupt:
        a.close()
        gevent.shutdown()
Example #24
0
def cleanup():
    shutdown_webfrontend()
    gateway.shutdown()
    gevent.shutdown()
Example #25
0
def _on_exit(server):
    gevent.shutdown()
Example #26
0
import gevent

def run_forever():
    gevent.sleep(1000)

def main():
    thread = gevent.spawn(run_forever)
    thread.join()

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print 'halt...'
        gevent.shutdown()
Example #27
0
File: server.py Project: befks/odoo
 def stop(self):
     import gevent
     self.httpd.stop()
     gevent.shutdown()
Example #28
0
 def stopProducing(self):
     self._headset.close()
     self._headset = None
     gevent.shutdown()
Example #29
0
def main():
    server = WSGIServer(('0.0.0.0', 5000), app)
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        gevent.shutdown()
Example #30
0
 def stop(self):
     import gevent
     self.httpd.stop()
     gevent.shutdown()
Example #31
0
 def clean_up(self):
     self.ppool.kill()
     self.tracker.hpool.kill()
     gevent.shutdown()
Example #32
0
 def stopProducing(self):
     self._headset.close()
     self._headset = None
     gevent.shutdown()
Example #33
0
 def run(self, num=10, timeout=60):
     self.timeout = timeout
     for i in xrange(num):
         g = gevent.spawn(self._fetch)
     g.join()
     gevent.shutdown()