cherrypy

CherryPy, Threads, and Member Variables; potential issues?

时光毁灭记忆、已成空白 提交于 2019-12-04 16:53:47
Let's say I have the following simple class: import cherrypy import os class test: test_member = 0; def __init__(self): return def index(self): self.test_member = self.test_member + 1 return str(self.test_member) index.exposed = True conf = os.path.join(os.path.dirname(__file__), 'config.ini') if __name__ == '__main__': # CherryPy always starts with app.root when trying to map request URIs # to objects, so we need to mount a request handler root. A request # to '/' will be mapped to HelloWorld().index(). cherrypy.config.update({'server.socket_host': '0.0.0.0'}) cherrypy.quickstart(test(),

Large file downloads in cherrypy

为君一笑 提交于 2019-12-04 16:31:17
I'm hosting a file access type website using Cherrypy, through uwsgi and nginx on a Raspberry Pi. One thing I've noticed is that if the file is rather large (let's say, about a gigabyte), uwsgi says it was killed by signal 9. This was remedied by putting a cherrypy.config.update({'tools.sessions.timeout': 1000000}) but this doesn't really solve the problem, as much as it is a bad hacky workaround that doesn't really work. It mainly just causes another problem by making the timeout very large. In addition, the browser cannot estimate how long it will take very accurately, and will end up

Profiling CherryPy

六月ゝ 毕业季﹏ 提交于 2019-12-04 12:01:31
I've been trying to start profiling my CherryPy webserver, but the documentation is lacking in detail in how this should be set up. I understand that I should be able to use cherrypy.lib.profiler as middleware to mount my initial server. Right now, I have code like the following: server_app = ServerClass() cherrypy.tree.mount(server_app, '/', '/path/to/config/file.cfg') cherrypy.engine.start() cherrypy.engine.block() I want to mount the profiling middleware, and it seems that something like the following is required: from cherrypy.lib import profiler server_app = ServerClass() server_cpapp =

saltstack 的 api

风格不统一 提交于 2019-12-04 09:43:07
上篇记录了 saltstack 的安装与配置和简单的使用,但是你会发现基本所有操作,都需要登录到 master机上进行命令行操作,虽然命令行才是最强大的,但是对于新手和入门时的学习使用和管理非常不友好。 然而 salt 已经为我们想到了,下面将为 saltstack 配置一个 web 界面,通过 web 界面来实现一些管理功能,由于 saltstack 官方本身时没有 web 界面的。 一、环境准备 系统为 centos7.2,python 版本为2.7 安装 salt-api [root@V1 ~]# yum install -y salt-api 二、具体配置 添加用户,用户 api 认证 [root@V1 ~]# useradd -M Amos 创建master的配置文件目录 [root@V1 ~]# mkdir /etc/salt/master.d 添加 api 的配置文件,同来配置 api 接口服务的端口和一些设定 [root@V1 ~]# cat /etc/salt/master.d/api.conf rest_cherrypy: port: 8000 debug: True #ssl_crt: /etc/pki/tls/certs/localhost.crt #ssl_key: /etc/pki/tls/certs/localhost.key disable_ssl:

win32com.client.Dispatch + Cherrypy = CoInitialize has not been called

我只是一个虾纸丫 提交于 2019-12-04 09:09:12
The following code works well, but it fails if executed from a CherryPy app method with the error message CoInitialize has not been called : import win32com.client xl = win32com.client.Dispatch("Excel.Application") xl.quit() This post suggests a solution that works for me: import pythoncom pythoncom.CoInitialize() The reason I'm asking about a problem for which I already have a solution, is that (1) I would like to know what I'm doing (rather than doing it only because I've seen it working once) and (2) I don't want to risk to miss something important (and reading this post makes me think that

Restart Python.py when it stops working

99封情书 提交于 2019-12-04 05:03:29
问题 I am using Cherrypy framework to run my python code on server. But the process stops working when the load increases. Every time this happens I have to manually go and start the python code. Is there any way i can use Gunicorn with Cherrypy so that Gunicorn can start the code automatically when it stops working. Any other solution will also work in this case. Just want to make sure that the python program does not stop working. 回答1: I use a cron that checks the memory load every few minutes

stopping a cherrypy server over http

懵懂的女人 提交于 2019-12-04 01:20:48
问题 I have a cherrypy app that I'm controlling over http with a wxpython ui. I want to kill the server when the ui closes, but I don't know how to do that. Right now I'm just doing a sys.exit() on the window close event but thats resulting in Traceback (most recent call last): File "ui.py", line 67, in exitevent urllib.urlopen("http://"+server+"/?sigkill=1") File "c:\python26\lib\urllib.py", line 87, in urlopen return opener.open(url) File "c:\python26\lib\urllib.py", line 206, in open return

CherryPy server name tag

杀马特。学长 韩版系。学妹 提交于 2019-12-04 01:13:46
问题 When running a CherryPy app it will send server name tag something like CherryPy/version. Is it possible to rename/overwrite that from the app without modifying CherryPy so it will show something else? Maybe something like MyAppName/version (CherryPy/version) 回答1: This can now be set on a per application basis in the config file/dict [/] response.headers.server = "CherryPy Dev01" 回答2: Actually asking on IRC on their official channel fumanchu gived me a more clean way to do this (using latest

Python (CherryPy) web app deployed locally, but not visible over intranet

ぐ巨炮叔叔 提交于 2019-12-03 23:55:27
I've created a Python web app using CherryPy, and have deployed in on my local machine. When I try to view it from another computer in the house, nothing comes back. However, if I create a simple html file, and deploy it with: $ python -m SimpleHTTPServer It is visible over the intranet. I'm stumped as to why my app could work locally, but not be avalable over the intranet, given that there is not a connection problem between these machines, and that I can serve other content on the same port. I have not used a configuration file, I'm using the default CherryPy settings. The default settings

How to return an image in an HTTP response with CherryPy

时光总嘲笑我的痴心妄想 提交于 2019-12-03 14:05:36
I have code which generates a Cairo ImageSurface , and I expose it like so: def preview(...): surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ... cherrypy.response.headers['Content-Type'] = "image/png" return surface.get_data() preview.exposed = True This doesn't work (browsers report that the image has errors). I've tested that surface.write_to_png('test.png') works, but I'm not sure what to dump the data into to return it. I'm guessing some file-like object? According to the pycairo documentation , get_data() returns a buffer. I've also now tried: tempf = os.tmpfile()