多处理Python开始处理时间偏移

时间:2016-11-01 14:06:50

标签: python multiprocessing

p = Pool(2)  
p.map(start_simulation, test_devices)

与上面的代码一样,我想用start_simulation函数启动两个worker,但有没有办法按时间间隔延迟它?例如:

worker1@start_simulation  
wait 5 minutes  
worker2@start_simulation

1 个答案:

答案 0 :(得分:0)

您可能更容易实施<?php require_once('./database/connect_bd.php'); function insert(){ $dbc = connection(); $returnn = array(); $errors = array(); $admin; $product; $record; $amount; if($_POST['product'] == ""){ $errors[] = 'The product field is required!'; }else{ $product = $_POST['product']; } if($_POST['admin'] == ""){ $errors[] = 'The admin field is required!'; }else{ $admin = $_POST['admin']; } if($_POST['record'] == ""){ $errors[] = 'The field record is required'; }else{ $record = $_POST['record']; } if(empty($_POST['amount'])){ $errors[] = 'The field amount is required'; }else{ $amount = $_POST['amount']; } if(empty($erros)){ $query = "select SUM(ret.amount) AS amount, ret.product_name, ret.id_product from(SELECT SUM(p.amount) AS AMOUNT, p.record_type, p.id_product, c.name AS name_product, c.image FROM stock p JOIN administrator u ON u.id_admin = p.id_admin JOIN register_products c ON c.id_product = p.id_product WHERE p.record_type = 'input' GROUP BY p.record_type, p.id_product, c.name, c.image UNION SELECT -SUM(p.amount) AS AMOUNT, p.record_type, p.id_product, c.name AS name_product, c.imagem FROM stock p JOIN administrator u ON u.id_admin = p.id_admin JOIN register_products c ON c.id_product = p.id_product WHERE p.record_type = 'output' GROUP BY p.record_type, p.id_product, c.name, c.image)ret WHERE ret.id_product = $product group by ret.name_product, ret.id_product"; $result = @mysqli_query($dbc, $query); $row = mysqli_fetch_array($result); $amount_db = $row['amount']; if($amount_db >= $amount || mysqli_num_rows($result) == 0){ $query = "INSERT INTO stock(id_stock, amount, record_type, id_admin, id_product, dt_drive) VALUES (NULL, $amount,'$record', '$admin' ,'$product',CURRENT_TIMESTAMP)"; $result = @mysqli_query($dbc, $query); if($result){ $returnn[] = 'successfully completed registration'; }else{ $errors[] = 'Some error occured while registering the stock!'; } }else{ //stock error echo"<script>alert('Value Exceeds amount in stock'); history.go(-1)</script>"; } }else{ $return = $errors; } return $returnn; }?>

multiprocessing.Process