python eventlet模块
来源:互联网 发布:襄阳蓝芯软件 编辑:程序博客网 时间:2024/04/27 23:08
python eventlet模块
python中更实用eventlet模块创建线程或者线程池。
def _func_on_containers(logger, conf, concurrency_key, func, **kwargs): """Run a function on each container with concurrency.""" bench = Bench(logger, conf, []) pool = eventlet.GreenPool(int(getattr(conf, concurrency_key))) for container in conf.containers: pool.spawn_n(func, bench.url, bench.token, container, **kwargs) pool.waitall()
eventlet模块内函数def spawn_n(self, function, *args, **kwargs): """Create a greenthread to run the *function*, the same as :meth:`spawn`. The difference is that :meth:`spawn_n` returns None; the results of *function* are not retrievable. """ # if reentering an empty pool, don't try to wait on a coroutine freeing # itself -- instead, just execute in the current coroutine current = greenthread.getcurrent() if self.sem.locked() and current in self.coroutines_running: self._spawn_n_impl(function, args, kwargs, None) else: self.sem.acquire() g = greenthread.spawn_n( self._spawn_n_impl, function, args, kwargs, True) if not self.coroutines_running: self.no_coros_running = event.Event() self.coroutines_running.add(g)def waitall(self): """Waits until all greenthreads in the pool are finished working.""" assert greenthread.getcurrent() not in self.coroutines_running, \ "Calling waitall() from within one of the " \ "GreenPool's greenthreads will never terminate." if self.running(): self.no_coros_running.wait()def spawn(func, *args, **kwargs): """Create a greenthread to run ``func(*args, **kwargs)``. Returns a :class:`GreenThread` object which you can use to get the results of the call. Execution control returns immediately to the caller; the created greenthread is merely scheduled to be run at the next available opportunity. Use :func:`spawn_after` to arrange for greenthreads to be spawned after a finite delay. """ hub = hubs.get_hub() g = GreenThread(hub.greenlet) hub.schedule_call_global(0, g.switch, func, args, kwargs) return gdef spawn_n(func, *args, **kwargs): """Same as :func:`spawn`, but returns a ``greenlet`` object from which it is not possible to retrieve either a return value or whether it raised any exceptions. This is faster than :func:`spawn`; it is fastest if there are no keyword arguments. If an exception is raised in the function, spawn_n prints a stack trace; the print can be disabled by calling :func:`eventlet.debug.hub_exceptions` with False. """ return _spawn_n(0, func, args, kwargs)[1]
0 0
- python eventlet模块
- python eventlet模块
- python eventlet
- Python eventlet
- python eventlet库 之一
- Python并发编程eventlet
- openstack 模块eventlet example code
- openstack 模块eventlet example code
- python eventlet并发原理分析
- python eventlet并发原理分析
- python eventlet并发原理分析
- eventlet
- eventlet
- eventlet
- eventlet引发的学习-python协程:eventlet[待续]
- python的并发库:asyncore和eventlet
- openstack任务eventlet和python的GIL
- eventlet引发的学习:python GIL
- rsync sersync2 文件实时双向同步
- Maven学习(二)- 安装m2eclipse插件
- Android基于源码分析Handler的消息机制
- 深入理解Linux修改hostname
- 通过zabora监控oracle
- python eventlet模块
- js中的this指针的用法
- /dev/mapper/vg_test-lv_root 占用到达100%的解决方法
- 联合索引 一例
- mybatis错误: Invalid bound statement
- prop()和attr()区别
- cocos2dx JAVA调用C++
- jquery-ui-multiselect 实现select下拉多选
- hibernate中报org.hibernate.MappingException: No Dialect mapping for JDBC type: -16错误