安装easy_install
安装pip easy_install pip
安装包:pip install celery
卸载包:pip uninstall celery
列出所有安装的包:pip freeze
更新包:pip install celery --upgrade
Python安装错误
1.安装celery时,依赖包billiard出现下面错误:
building '_billiard' extension error: Unable to find vcvarsall.bat
解决方法:安装Microsoft Visual C++ 2008 Express Edition
或:安装MinGW-5.0.2.exe,将C:\MinGW\bin\mingw32-make.exe复制并重命名为make.exe,将C:\MinGW\bin添加到环境变量。
2.启动Celery时,出现下面错误信息:
[2012-08-18 10:32:19,282: ERROR/MainProcess] Consumer: Connection Error: [Errno10061] . Trying again in 2 seconds...
原因:连接不上rabbitmq服务器
解决方法:启动rabbitmq
3.启动Celery时,出现下面错误信息:
ValueError: Couldn't import 'celery.worker.strategy:default': 'latin-1' codec can't encode characters in position 0-4: ordinal not in range(256)。
原因:如果你使用自定义时区,需要安装pytz库
解决方法:pip install pytz
[2012-08-19 18:35:16,173: ERROR/MainProcess] Task import_onu_task.import_temp_on
us[c059b91e-62c9-4bd4-84d3-96e092f2a5a0] raised exception: (2006, 'MySQL server
has gone away')
Traceback (most recent call last):
File "E:\Python27\lib\site-packages\celery\task\trace.py", line 212, in trace_
task
R = retval = fun(*args, **kwargs)
File "D:\opengoss\epon-web\python_tasks\import_onu_task.py", line 35, in impor
t_temp_onus
success,update, error_result = handle_onu(conn, cursor,onu_sheet,onu_dict,en
trance_dict,user_id,permits,permit_olt_dict)
File "D:\opengoss\epon-web\python_tasks\import_onu_task.py", line 118, in hand
le_onu
success_num = cursor.executemany(insert_sql, insert_results)
File "E:\Python27\lib\site-packages\MySQLdb\cursors.py", line 223, in executem
any
r = self._query('\n'.join([query[:p], ',\n'.join(q), query[e:]]))
File "E:\Python27\lib\site-packages\MySQLdb\cursors.py", line 317, in _query
rowcount = self._do_query(q)
File "E:\Python27\lib\site-packages\MySQLdb\cursors.py", line 281, in _do_quer
y
db.query(q)
OperationalError: (2006, 'MySQL server has gone away')
使用mysql ping来检查连接,实现超时自动重新连接
conn.ping(True)
[2012-08-19 18:42:11,154: ERROR/MainProcess] Task import_onu_task.import_temp_on
us[052f045a-f396-4bfe-827e-be4bea2b1c93] raised exception: (1153, "Got a packet
bigger than 'max_allowed_packet' bytes")
Traceback (most recent call last):
File "E:\Python27\lib\site-packages\celery\task\trace.py", line 212, in trace_
task
R = retval = fun(*args, **kwargs)
File "D:\opengoss\epon-web\python_tasks\import_onu_task.py", line 36, in impor
t_temp_onus
success,update, error_result = handle_onu(conn, cursor,onu_sheet,onu_dict,en
trance_dict,user_id,permits,permit_olt_dict)
File "D:\opengoss\epon-web\python_tasks\import_onu_task.py", line 119, in hand
le_onu
success_num = cursor.executemany(insert_sql, insert_results)
File "E:\Python27\lib\site-packages\MySQLdb\cursors.py", line 223, in executem
any
r = self._query('\n'.join([query[:p], ',\n'.join(q), query[e:]]))
File "E:\Python27\lib\site-packages\MySQLdb\cursors.py", line 317, in _query
rowcount = self._do_query(q)
File "E:\Python27\lib\site-packages\MySQLdb\cursors.py", line 281, in _do_quer
y
db.query(q)
OperationalError: (1153, "Got a packet bigger than 'max_allowed_packet' bytes")
C:\Program Files\MySQL\MySQL Server 5.1\my.ini 最后一行加上
max_allowed_packet=32M
Mysql重启:/etc/inint.d/mysqld restart