我正在使用Gunicorn服务于我的烧瓶web应用程序。我的网络应用发送了一些请求,要求下载超过10GB的巨大文件,这需要一段时间才能完成。我正在使用生成器将进度输出流回到网页,因此连接保持打开状态,直到下载完成。我的问题是Gunicorn将在一定数量的秒后超时。
我将超时配置为更长,如下所示:
/usr/bin/gunicorn -c /my/dir/to/app/gunicorn.conf -b 0.0.0.0:5000 wsgi --timeout 90
Run Code Online (Sandbox Code Playgroud)
但是我不知道要花多长时间,所以如果下载的文件越来越大,我必须不断更改此超时时间。
我想知道是否有一种方法可以全部禁用超时,或者是否还有其他方法可以补救较长的下载时间。
我在其中定义了通用装置,conftest.py这些装置在所有模块之间共享,并且作用范围为“功能”范围,如下所示:
测试.py
@pytest.fixture(scope="function")
def reset_state(services):
# resets the state of the services
Run Code Online (Sandbox Code Playgroud)
我的测试目前将其称为如下,
测试模块一:
# change scope to session here
@pytest.mark.usefixtures("reset_state")
def test_something:
# Test stuff using session-scoped fixtures.
Run Code Online (Sandbox Code Playgroud)
对于上述具体测试,我想将通用夹具的范围更改reset_state为“会话”。
有没有办法在运行时更改范围?
我正在尝试设置我的远程服务器,并让Anisble安装所需的软件包。在我看来,playbook.yml一切正常,除非它尝试requirments.txt仅安装在一台远程服务器上。它给了我以下错误:
FAILED! => {"changed": false, "msg": "No setuptools found in remote host, please install it first."}
Run Code Online (Sandbox Code Playgroud)
是的,我确实已setuptools安装在远程主机上。
# pip3 show setuptools
Name: setuptools
Version: 40.4.3
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://github.com/pypa/setuptools
Author: Python Packaging Authority
Author-email: distutils-sig@python.org
License: UNKNOWN
Location: /usr/lib/python3.6/site-packages
Requires:
Required-by: pipenv
Run Code Online (Sandbox Code Playgroud)
不知道为什么在使用pip3进行安装时甚至需要setuptools。
这是我的剧本摘要:
- name: Install requirements
pip:
requirements: /.supv/bridge_modules/requirements.txt
executable: pip3
Run Code Online (Sandbox Code Playgroud)
似乎在其他远程主机上工作正常,只是这有问题。我尝试卸载setuptools并重新安装,仍然没有运气。有任何想法吗?
我有一个枚举定义如下:
export enum taskTypes {
WORK = 'work',
SLEEP = 'sleep',
EXERCISE = 'exercise',
EAT = 'eat'
}
Run Code Online (Sandbox Code Playgroud)
在我的班级的顶部,我定义currentTask如下:
private currentTask: string;
Run Code Online (Sandbox Code Playgroud)
但是,当我在中使用枚举时,[WORK, SLEEP].includes(currentTask)出现以下错误。
Argument of type 'string' is not assignable to parameter of type 'currentTask'
奇怪的是,当我只是将它更改为使用实际字符串时,它不会抱怨。
['work', 'sleep'].includes(currentTask) ===> 这有效。
那么我在这里错过了什么?
我在从主查询函数进行子查询时遇到问题。我的查询是这样的类中的一个函数
class MyClass():
...
...
@property
def main_query(self):
main_query = session.query(MainTable)
.join(otherTable)
.filter(otherTable.id = self.id)
return main_query
Run Code Online (Sandbox Code Playgroud)
出于某种原因,当我尝试在另一个模块中执行如下简单的操作时:
q = MyClass.main_query(111) # 111 is the id here
print(str(q)) # I can see this print, it prints the correct query statement
subquery_maxdate = session.query(func.max(Table1.date).label("max_date")).subquery()
query = DBSession.query(q, subquery_maxdate) #This gives me an error
AttributeError: 'Query' object has no attribute 'is_clause_element'
Run Code Online (Sandbox Code Playgroud)
我试图从main_query取决于用户的下拉选择中分离子查询。
似乎我无法从类中运行另一个查询,因为当我只是尝试这样做时:
q = DBSession.query(q) # This already gives me the error
AttributeError: 'Query' object has no attribute 'is_clause_element' …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 Flask webapp,在开发过程中我使用run.py.
运行.py:
from my_app import app
from my_app.config import (WEBSERVER_PORT)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=WEBSERVER_PORT, debug=True)
Run Code Online (Sandbox Code Playgroud)
但是,我计划在生产中使用 gunicorn 为我的应用程序提供服务,并且当我使用 gunicorn 运行该应用程序时,我看到了性能下降。例如,我向我的 web 应用程序添加了一个新按钮,但我只能看到run.py用于运行该应用程序的新按钮。但是当我使用 gunicorn 为我的应用程序提供这样的服务时:
gunicorn --bind 0.0.0.0:8000 wsgi
Run Code Online (Sandbox Code Playgroud)
该应用程序运行没有错误,但是,我没有看到新按钮。这是我的 wsgi.py:
from my_app import app as application
if __name__ == "__main__":
application.run()
Run Code Online (Sandbox Code Playgroud)
这是我的服务方式:
(venv)# gunicorn --bind 0.0.0.0:8000 wsgi
[2018-11-19 10:35:52 -0800] [16644] [INFO] Starting gunicorn 19.9.0
[2018-11-19 10:35:52 -0800] [16644] [INFO] Listening at: http://0.0.0.0:8000 (16644)
[2018-11-19 10:35:52 -0800] [16644] [INFO] Using worker: sync …Run Code Online (Sandbox Code Playgroud) 我在基本配置中设置了两个日志处理程序。记录FileHandler到文件并StreamHandler记录到标准输出。
logging.basicConfig(
format="%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s",
level=logging.INFO,
handlers=[
logging.FileHandler("/my/log/file.log"),
logging.StreamHandler(sys.stdout)
]
)
Run Code Online (Sandbox Code Playgroud)
目前,上面的代码工作正常,但是,我希望StreamHandler输出不同的格式,只是%(message).
有没有办法在 my 中指定这一点logging.basicConfig?
在javascript中,存在对象解构,因此,如果中间对象被重用多次,我们可以分解对象并仅使用end键。例如)
const person = {
firstName: "Bob",
lastName: "Marley",
city: "Space"
}
Run Code Online (Sandbox Code Playgroud)
因此,person.<>与其调用获取每个值,不如将其分解
console.log(person.firstName)
console.log(person.lastName)
console.log(person.city)
Run Code Online (Sandbox Code Playgroud)
变形:
const { firstName, lastName, city } = person;
Run Code Online (Sandbox Code Playgroud)
并这样调用:
console.log(firstName)
console.log(lastName)
console.log(city)
Run Code Online (Sandbox Code Playgroud)
Java中有类似的东西吗?我有这个Java对象,我需要从中获取值,并且必须像这样调用长的中间对象名称:
myOuterObject.getIntermediateObject().getThisSuperImportantGetter()
myOuterObject.getIntermediateObject().getThisSecondImportantGetter()
...
Run Code Online (Sandbox Code Playgroud)
我想这个解构它在某种程度上,只是调用的最后一个方法getThisSuperImportantGetter(),getThisSecondImportantGetter()更清洁的代码。
我正在尝试使用redux设置反应导航v3。在react navigation文档中,我可以成功设置导航,并且无需添加redux即可正常运行。但是,当我尝试添加我的redux class App extends React.Component{...}并连接我的操作时,它将引发以下错误:
永久违反:永久违反:在“ Connect(AuthScreen)”的上下文中找不到“ store”。将根组件包装在中,或者将自定义React上下文提供程序传递给connect选项中的Connect(AuthScreen)并将相应的React上下文使用者传递给Connect(AuthScreen)。
App.js
const MainNavigator = createBottomTabNavigator({
welcome: { screen: WelcomeScreen },
auth: { screen: AuthScreen },
main: {
screen: createBottomTabNavigator({
map: { screen: MapScreen },
deck: { screen: DeckScreen },
review: {
screen: createStackNavigator({
review: { screen: ReviewScreen },
settings: { screen: SettingsScreen }
})
}
})
}
});
const AppContainer = createAppContainer(MainNavigator);
class App extends React.Component {
render() {
return (
<Provider store={store}>
<AppContainer />
</Provider>
);
}
}
export …Run Code Online (Sandbox Code Playgroud) 我习惯用java样板在方法顶部检查输入参数:
public static Boolean filesExist(String file1, String file2, String file3 ... ) {
if (file1 == null || file2 == null || file3 == null ||...) {
throw new IllegalArgumentException();
}
if (another_param == null) {
throw new NullPointerException();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我正在阅读Java 8的可选参数,并注意到我们可以改为执行以下操作:
Optional.ofNullable(file1).orElseThrow(IllegalArgumentException::new);
Optional.ofNullable(file2).orElseThrow(IllegalArgumentException::new);
Optional.ofNullable(another_param).orElseThrow(NullPointerException::new);
...
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,第二种方法是否有任何弊端,我觉得它对我来说看起来更干净一些。
python-3.x ×6
gunicorn ×2
java ×2
ansible ×1
fixtures ×1
flask ×1
java-8 ×1
javascript ×1
logging ×1
object ×1
optional ×1
pip ×1
pytest ×1
python ×1
react-native ×1
react-redux ×1
reactjs ×1
sqlalchemy ×1
typescript ×1