I am opening a file which has 100,000 URL's. I need to send an HTTP request to each URL and print the status code. I am using Python 2.6, and so far looked at the many confusing ways Python implements threading/concurrency. I have even looked at the python concurrence library, but cannot figure out how to write this program correctly. Has anyone come across a similar problem? I guess generally I need to know how to perform thousands of tasks in Python as fast as possible - I suppose that means 'concurrently'.

我试图理解什么使得锁在并发如此重要,如果一个人可以使用同步(这)。在下面的虚拟代码中,我可以这样做:

同步整个方法或同步脆弱区域(Synchronized (this){…}) 或者使用ReentrantLock锁定易受攻击的代码区域。

代码:

    private final ReentrantLock lock = new ReentrantLock(); 
    private static List<Integer> ints;

    public Integer getResult(String name) { 
        .
        .
        .
        lock.lock();
        try {
            if (ints.size()==3) {
                ints=null;
                return -9;
            }   

            for (int x=0; x<ints.size(); x++) {
                System.out.println("["+name+"] "+x+"/"+ints.size()+". values >>>>"+ints.get(x));
            }

        } finally {
            lock.unlock();
        } 
        return random;
}

我还没有看到Pool用例的清晰示例。运用,池。apply_async和Pool.map。我主要使用Pool.map;其他人的优势是什么?

并行编程和并行编程的区别是什么?我问了谷歌,但没有找到任何帮助我理解这种区别的东西。你能给我举个例子吗?

现在我找到了这个解释:http://www.linux-mag.com/id/7411 -但是“并发性是程序的属性”vs“并行执行是机器的属性”对我来说还不够-我仍然不能说什么是什么。

互斥锁类很容易被误解,而全局互斥锁更是如此。

在创建全局互斥对象时使用什么是好的、安全的模式?

一个会起作用的

不管我的机器在什么地方 是否保证正确释放互斥锁 如果没有获取互斥锁,则可选地不会永远挂起 处理其他进程放弃互斥锁的情况

信号量是一种编程概念,经常用于解决多线程问题。我对社区的问题是:

什么是信号量,如何使用它?

有人能告诉我同步方法比同步块的优势与一个例子吗?

我目前正在寻找其他搜索方法,而不是有一个巨大的SQL查询。 我最近看了elasticsearch,玩了一下whoosh(一种搜索引擎的Python实现)。

你能给出你的选择的理由吗?

我需要一次执行一定数量的任务4,就像这样:

ExecutorService taskExecutor = Executors.newFixedThreadPool(4);
while(...) {
    taskExecutor.execute(new MyTask());
}
//...wait for completion somehow

当所有这些都完成后,我如何得到通知?现在我想不出比设置一些全局任务计数器更好的方法,并在每个任务结束时减少它,然后在无限循环中监视这个计数器变成0;或获取一个期货列表,并在无限循环监视器isDone为所有它们。不涉及无限循环的更好的解决方案是什么?

谢谢。

这是否意味着两个线程不能同时更改底层数据?或者它是否意味着当多个线程执行给定的代码段时,该代码段将以可预测的结果运行?