我的网络抓取程序需要大约10分钟的时间来运行,我试图使用线程库让我的网络抓取程序在数据返回给调用Flask创建的API的人之后在后台运行。
我的代码如下:
#define ROWS 30
#define COLS 30
#define MAXLINE 512
int prams[ROWS][COLS];
int row, col, len;
char buffer[MAXLINE], *p;
row = 0;
while (row < ROWS && fgets(buffer, MAXLINE, stdin)) {
col = 0;
p = buffer;
while (col < COLS && sscanf(p, "%d %n", &prams[row][col], &len) > 0) {
p += len;
++col; }
if (*p) {
/* extra stuff on the end of the line -- error? */ }
++row; }
现在我正在用邮递员测试我的API,当我发出POST请求时,它会打印出“ init”,但似乎并没有进一步启动from threading import Thread
from flask import Flask
application = Flask(__name__)
class Compute(Thread):
def __init__(self, request):
print("init")
Thread.__init__(self)
self.request = request
def run(self):
print("RUN")
command = './webscrape.py -us "{user}" -p "{password}" -url "{url}"'.format(**self.request.json)
output = subprocess.call(['bash','-c', command])
@application.route('/scraper/run', methods=['POST'])
def init_scrape():
thread_a = Compute(request.__copy__())
thread_a.start()
return jsonify({'Scraping this site: ': request.json["url"]}), 201
if __name__ == '__main__':
application.run(host="0.0.0.0", port="8080")
函数,我在做什么错? / p>