0
我有程序,其中:在PHPPHP系统()挂起?
- 运行无限循环,在那里我获得新的记录过程中,文件保存
- 执行python脚本,池脚本进程这个记录
PHP代码:
while(true) {
$records = get_records();
file_put_contents($file_name, json_encode($records));
echo "php:system:before";
system("python script.py $file_name");
echo "php:system:before";
}
Python代码:
import json
import os
import sys
import time
import random
import urllib2
from multiprocessing import Pool, freeze_support
from subprocess import Popen, PIPE
from os.path import isdir
from platform import system
from lib import Logger
def do_something(record):
# ... some operations
print("python:record:done")
if __name__ == '__main__':
records = read_records
pool = Pool(4)
pool.map(do_something, records)
pool.close()
pool.join()
print("python:done")
但时不时的进程挂起。
我的日志:
php:system:start
python:record:done
python:record:done
python:record:done
python:record:done
python:record:done
python:record:done
python:record:done
python:done
<- here I expect php:system:before
但一天两次我不明白这一点,我重置程序。 错误在哪里,为什么脚本挂起?
你确定这是运行Apache的背后?看起来更像是一个shell脚本/ cronjob。 – smassey 2014-09-29 08:46:55
它在Windows 7上从命令行运行。 – krynio 2014-09-29 08:50:17
啊好的。你为什么使用PHP这一点,其余的蟒蛇?为什么不使用python – Bowersbros 2014-09-29 08:57:15