我有一个django站点,我需要使用子进程调用脚本.当我使用ascii字符时,子进程调用工作但当我尝试发出utf-8编码的参数时,我收到一个错误:
execv() arg 2 must contain only strings.
Run Code Online (Sandbox Code Playgroud)
该字符串u'Wiadomo\u015b\u0107'
来自postgres数据库.这个例子使用了波兰语.当我用英语单词运行时,我没有问题.
电话看起来像这样:
subprocess.Popen(['/usr/lib/p3web2/src/post_n_campaigns.py', '-c', u'bm01', '-1', u'Twoja', '-2', u'Wiadomo\u015b\u0107', '-3', u'', '-4', u'', '-5', u'', '-6', u'', '-m', u'pl', '-p', 'yes'])
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我不确定如何处理字符串.奇怪的是,当我通过python解释器运行它时,这工作正常.
我有一个现有的cherrypy应用程序,但我想知道是否可以在gevent wsgi服务器上运行它.我想我可以但我没有访问linux服务器来测试gevent并且无法让它在我的mac上运行.
我认为这是可能的,因为每一方都遵循wsgi规范.
有没人试过这个?
我猜一个例子如下所示:
import cherrypy
from gevent import wsgi
class Root(object):
def index(self):
return "hi!"
index.exposed = True
app = cherrypy.tree.mount(Root(), '/')
wsgi.WSGIServer(('', 8088), app).serve_forever()
Run Code Online (Sandbox Code Playgroud) 我的一些工作线程存在问题.我在线程的run方法中添加了一个catchall异常语句,如下所示:
try:
"""Runs the worker process, which is a state machine"""
while self._set_exitcode is None :
assert self._state in Worker.STATES
state_methodname = "_state_%s" % self._state
assert hasattr(self, state_methodname)
state_method = getattr(self, state_methodname)
self._state = state_method() # execute method for current state
self._stop_heartbeat()
sys.exit( self._set_exitcode )
except:
self.log.debug(sys.exc_info())
Run Code Online (Sandbox Code Playgroud)
我读到这是捕获可能导致问题而不是使用的所有内容的事实方法Exception, e
.由于这种方法,我发现了一些很小的错误,但我的问题是工人们仍在死亡,我不知道如何进一步记录正在发生的事情或排除故障.
任何想法将不胜感激.
谢谢!
我有一个奇怪的问题.我可以从命令行使用psql连接到远程主机,但不能在django设置文件中使用完全相同的凭据.我收到错误:
无法连接到服务器:权限被拒绝服务器是否在主机"remote ip"上运行并接受端口port_number上的TCP/IP连接?
如果我可以使用psql连接而不使用django我在这里缺少什么?我还检查了python解释器,我可以加载psycopg2.
任何帮助都非常感谢,因为我在网上找到的并没有帮助.
干杯,
d
这是settings.py中的db conf
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<db name goes here>', # Or path to database file if using sqlite3.
'USER': '<db user>', # Not used with sqlite3.
'PASSWORD': '<pswd goes here>', # Not used with sqlite3.
'HOST': '<remote ip goes here>',
'PORT': '5432',
}
Run Code Online (Sandbox Code Playgroud) 我首先尝试使用解释器用python的uuid模块生成uuid.我做了以下事情:
>>>import uuid
>>>uuid.uuid1()
UUID('d8904cf8-48ea-11e0-ac43-109add570b60')
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.我创建了一个简单的小函数来生成uuid.
import uuid
def get_guid():
return uuid.uuid1()
if __name__ == '__main__':
print get_guid()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
AttributeError:'module'对象没有属性'uuid1'
好的......嗯......回到口译员,现在它也被打破了.我得到相同的错误运行我用来测试它的相同代码.我很困惑.是什么让uuid像这样打破?我的代码出了什么问题?
我正在使用python 2.6
我对 celery 的记录器有问题。我有一个渲染帧的函数。我记录了我生成的子进程的输出,但似乎只有每个工作人员从队列中挑选的第一个作业被写入。队列中的所有后续任务都不会生成日志文件。我也尝试过使用 python 自己的日志记录,但发生了同样的问题。是否有我可能缺少的配置?
@task(queue='rndr')
def rndr(params):
path = get_logger_path(params)
logger = rndr.get_logger(logfile=path)
return render(params, logger)
Run Code Online (Sandbox Code Playgroud)
我以这种方式定义我的任务,因为我的重试记录器的定义不同,即 rndr_retry.get_logger ...
我的 celeryconfig 如下所示:
BROKER_HOST = "xxx.xxx.xxx.xxx"
BROKER_PORT = 5672
BROKER_USER = "xxxx"
BROKER_PASSWORD = "xxxx"
CELERY_RESULT_BACKEND = 'amqp'
CELERY_DISABLE_RATE_LIMITS = True
CELERY_ACKS_LATE = True
CELERY_IMPORTS = ['lib.tasks.concatenate', 'lib.tasks.encode', 'lib.tasks.render', 'lib.tasks.still_image', 'lib.tasks.retry']
CELERY_ROUTES = {'lib.tasks.encode':{'queue': 'encode'},
'lib.tasks.concatenate':{'queue': 'encode'},
'lib.tasks.still_image':{'queue': 'encode'},
'lib.tasks.render':{'queue':'rndr'},
'lib.tasks.retry':{'queue': 'retry'}
}
Run Code Online (Sandbox Code Playgroud)
希望有人能解释为什么只有队列中的第一个任务会写...
先感谢您。
更新:根据要求,这里是渲染方法的部分版本,没有所有细节......
def render(params, logger):
#load params to local values
try:
#create subprocess
output = child_proc.communicate()[0] …
Run Code Online (Sandbox Code Playgroud) python ×4
celery ×1
cherrypy ×1
django ×1
gevent ×1
logging ×1
postgresql ×1
subprocess ×1
unicode ×1
uuid ×1