系统规范 - MacOS 10.13.6 - Python 3.7.0 - Tornado 5.1.1
我想使用 ThreadPoolExecutor 在提供 RESTful 服务的 Tornado 实例中运行阻塞函数。
ThreadPool 会按预期工作并并行生成四个工作线程(请参阅下面的代码和控制台日志),只要我不试图产生由执行的函数返回的结果。
ThreadPoolExecutor 不产生结果
import time
import tornado.web
from tornado.concurrent import run_on_executor
from concurrent.futures import ThreadPoolExecutor
from tornado.ioloop import IOLoop
MAX_WORKERS = 4
i = 0
class Handler(tornado.web.RequestHandler):
executor = ThreadPoolExecutor(max_workers=MAX_WORKERS)
@run_on_executor
def background_task(self, i):
print("going sleep %s" % (i))
time.sleep(10);
print("waking up from sleep %s" % (i))
return str(i)
@tornado.gen.coroutine
def get(self):
global i
i+=1
self.background_task(i)
def make_app():
return tornado.web.Application([
(r"/", Handler), …Run Code Online (Sandbox Code Playgroud) 嗨我需要一些基本身份验证的帮助,而ajax get/post请求到python baseHTTPserver.
我能够在python脚本中更改一些代码行来发送CORS头.当我禁用http base authentification时,它在现代浏览器中工作正常.
如果启用了身份验证,我会收到501(不支持的方法('OPTIONS'))错误(i chrome).
我花了好几个小时找到一个解决方案,现在我认为我是一个好方法.正如我在下面的主题中所读到的,HTTPRequestHandler可能会导致问题,但我的pyton技能不足以解决问题.
如果在这里和这里找到一些关于这个主题的帖子,但是我无法使用我的脚本运行它.有人可以帮助我让它运行吗?
任何帮助或想法都将受到高度赞赏.
# Copyright 2012-2013 Eric Ptak - trouch.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on …Run Code Online (Sandbox Code Playgroud) 还请在底部查看我的更新
我在Chrome中执行跨域jQuery.ajax GET REQUEST时遇到一些问题.
预战非常长(最多20秒),而在Firefox中运行良好.
我尝试了不同的技巧(例如启用异步),但我无法管理.响应是一个json对象数组,并不是很大(只有几个字节).
这个问题似乎只在第一次通话时出现.我做了一个再次执行请求的函数.它由成功处理程序执行.从最小12秒开始第一次延迟后,请求执行正常.
我已经尝试过不同版本的jQuery(因为我是第一次使用2.0.3).
我登录了服务器.正如想象的那样,OPTION请求最多不会执行20秒.没有服务器问题.服务器完全根据延迟识别命令并执行GET方法.
对于页面加载2014-01-11 14:59:00我的日志输出如下:
2014-01-11 14:59:14 - log.txt - "OPTIONS /unit/IO/*?_=1389452340572 HTTP/1.1" 200 -
2014-01-11 14:59:14 - log.txt - "GET /unit/IO/*?_=1389452340572 HTTP/1.1" 200 -
2014-01-11 14:59:14 - log.txt - "OPTIONS /unit/IO/*?_=1389452340573 HTTP/1.1" 200 -
2014-01-11 14:59:14 - log.txt - "GET /unit/IO/*?_=1389452340573 HTTP/1.1" 200 -
Run Code Online (Sandbox Code Playgroud)
这是我的ajax电话:
$.ajax({
url: <<crossdomain>>,
type: 'GET',
contentType:'application/json',
async:true,
cache:false,
beforeSend: function (request)
{
request.setRequestHeader("Authorization", 'Basic ' + encodedData);
},
success: function(response) {
alert(response)
}
});
Run Code Online (Sandbox Code Playgroud)
请求标头(Chrome):
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4 …Run Code Online (Sandbox Code Playgroud) 我开始学习C++编程,并对错误处理有疑问.
我做了从函数计算x代码ax+b=0(所以我必须要划分-b的a).用户通过输入值cin >>
如果我除以0,我得到-int我的输出.是否有可能捕获错误(例如在if声明中)?
我知道除以零是不可能的,我也知道如果不检查用户的输入(例如if ((a != 0)){calculate}),它不会是一个好的行为形成一个程序.问题是我想知道如何/如何捕获此错误;-)它是否依赖于硬件,操作系统或编译器?
我的老师帮不了我;)
顺便说一句.我在Mac OS X 10.8.2上使用Eclipse Juno IDE for C/C++
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
float a, b, x; //float da Kommazahlen erwartet werden
cout << "ax + b = 0" << '\n'<< endl;
cout << "Bitte geben Sie einen Wert für a ein:" << endl;
cin >> a;
cout << "Bitte geben Sie einen …Run Code Online (Sandbox Code Playgroud)