python 多线程高效编程技巧13(如何在线程之间实现

&nbsp>&nbsp
&nbsp>&nbsp
&nbsp>&nbsp
python高效编程技巧8(如何实现可迭代对象和迭代器对象)
摘要:#!/usr/bin/envpython#-*-coding:utf-8-*-#=========说明:如果某个对象是可迭代对象,则使用iter方法可以得到该对象的迭代器对象=========l=[1,2,3,4]printiter(l)s=&abcdef&printiter(s)#为什么列表和字符串是可迭代对象?因为list有__iter()__方法,字符串有__getitem__()方法,#在使用iter()函数来调用List或者string的时候,实
#!/usr/bin/env python# -*- coding:utf-8 -*-# =========说明:如果某个对象是可迭代对象,则使用iter方法可以得到该对象的迭代器对象=========l = [1, 2, 3, 4]print iter(l)s = &abcdef&print iter(s)# 为什么列表和字符串是可迭代对象?因为list有__iter()__方法,字符串有__getitem__()方法,# 在使用iter()函数来调用List或者string的时候,实际上是调用了这两个方法print l.__iter__()print s.__getitem__(1)# =========迭代器对象:=========t = iter(l)print t.next()
以上是的内容,更多
的内容,请您使用右上方搜索功能获取相关信息。
若你要投稿、删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内给你回复。
云服务器 ECS
可弹性伸缩、安全稳定、简单易用
&40.8元/月起
预测未发生的攻击
&24元/月起
邮箱低至5折
推荐购买再奖现金,最高25%
&200元/3月起
你可能还喜欢
你可能感兴趣
阿里云教程中心为您免费提供
python高效编程技巧8(如何实现可迭代对象和迭代器对象)相关信息,包括
的信息,所有python高效编程技巧8(如何实现可迭代对象和迭代器对象)相关内容均不代表阿里云的意见!投稿删除文章请联系邮箱:zixun-group@service.aliyun.com,工作人员会在五个工作日内答复
售前咨询热线
支持与服务
资源和社区
关注阿里云
International知识在于积累
python高效编程技巧14(如何使用线程池)
from concurrent.futures import ThreadPoolExecutor
如何使用线程池:
使用标准库中的concurrent.futures下的ThreadPoolExecutor对象
的submit和map方法可以用来启动线程池中线程执行任务
当线程池中的每个线程都在运行,又有一个新的线程来调用的时候,则这个多的线程会等待线程池中有空余的线程时才会执行
executor = ThreadPoolExecutor(3)
def f(a, b):
return a ** b
future = executor.submit(f, 2, 3)
print future.result()
future = executor.map(f, [2, 3, 5], [4, 5, 6])
for result in future:
print result
扫码向博主提问
非学,无以致疑;非问,无以广识
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!此处仅供自己课后笔记所用,大家对我博文可以持有怀疑态度。。。
事件通知方
package com.common.
import java.util.C
import java.util.I
import java.util.M
import org.springframework.context.ApplicationC
import com.common.web.AppC
public class EventSource {
protected Class&? extends EventListener&?&& listenerI
public EventSource(Class&? extends EventListener&?&& listenerIntf){
if (listenerIntf == null){
throw new IllegalArgumentException("ListenerIntf should not be null!");
String baseListenerPackageName = EventListener.class.getPackage().getName();
if (listenerIntf.getCanonicalName().equals(baseListenerPackageName + ".EventListener")){
throw new IllegalArgumentException("Module business should define it's own EventListener!");
this.listenerIntf = listenerI
public EventSource(){
public void sendNotify() {
ApplicationContext applicationContext =
AppContext.getContext();
if (listenerIntf == null){
throw new NullPointerException("listenerIntf should not null!");
Map&String, ?& map = applicationContext.getBeansOfType(listenerIntf);
if (map != null && !map.isEmpty()){
Collection&?& classes = map.values();
Iterator&?& iterator = classes.iterator();
while (iterator.hasNext()){
@SuppressWarnings("unchecked")
EventListener&EventSource& listener = (EventListener&EventSource&)iterator.next();
listener.handleEvent(this);
事件接收方:
public interface EventListener&T extends EventSource& extends java.util.EventListener {
public void handleEvent(T eventSource);
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!网站当前访问量较大,请输入验证码后继续访问
(输入图中的字符,不区分大小写)Python高效编程技巧实战
有偿个人demo: http://www.chenzhuo.ltd/loveshare/
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!}

我要回帖

更多关于 python 多线程 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信