【发布时间】:2026-01-31 02:00:01
【问题描述】:
我有程序在哪里:
- 在 php 中运行无限循环,获取新记录进行处理,保存在文件中
- 在池脚本处理此记录的位置运行 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
但是一天两次我没有得到它,我重置了程序。 错误在哪里,为什么脚本会挂起?
【问题讨论】: