小编Yak*_*hay的帖子

How to use python multiprocessing module in django view

I have a simple function that go over a list of URLs, using GET to retrieve some information and update the DB (PostgresSQL) accordingly. The function works perfect. However, going over each URL one at a time talking too much time.

Using python, I'm able to do to following to parallel these tasks:

from multiprocessing import Pool

def updateDB(ip):
     code goes here...

if __name__ == '__main__':
    pool = Pool(processes=4)              # process per core
    pool.map(updateDB, ip)
Run Code Online (Sandbox Code Playgroud)

This is working …

python django multiprocessing

6
推荐指数
2
解决办法
2万
查看次数

在div边框内设置动画图像

我正在尝试动画一个应该在div容器边框内随机移动的图像.我在这里找到了一些设置动画边框的解决方案,但是在图像停留在div中的地方没有.

我有一个例子 - 我需要红色方块在黄色div内移动,即使我向下滚动页面.

我怎样才能做到这一点?

$(document).ready(function() {
    animateDiv();

});

function makeNewPosition($container) {

    // Get viewport dimensions (remove the dimension of the div)
    $container = ($container || $(window))
    var h = $container.height() - 50;
    var w = $container.width() - 50;

    var nh = Math.floor(Math.random() * h);
    var nw = Math.floor(Math.random() * w);

    return [nh, nw];

}

function animateDiv() {
    var $target = $('.a');
    var newq = makeNewPosition($target.parent());
    var oldq = $target.offset();
    var speed = calcSpeed([oldq.top, oldq.left], newq);

    $('.a').animate({
        top: newq[0],
        left: …
Run Code Online (Sandbox Code Playgroud)

html javascript css jquery

5
推荐指数
1
解决办法
92
查看次数

标签 统计

css ×1

django ×1

html ×1

javascript ×1

jquery ×1

multiprocessing ×1

python ×1