社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Py站长  »  全部回复
回复总数  988
10 年前
回复了 Py站长 创建的主题 » django 批量插入的时候 如何解决重复值得问题?

一个简单的做法就是 以所有KEY的ID LIST 集合A去查询出对象集合B,然后 A-B 获取差集 C,然后插入C就行了。 可能需要使用事务,否则可能会有并发问题。

10 年前
回复了 Py站长 创建的主题 » python 语音程序怎么写

http://www.taiv5.com/search?q=Python%20Dragonfly

https://pypi.python.org/pypi/dragonfly

试试这个

10 年前
回复了 Py站长 创建的主题 » 五步教你实现使用Nginx+uWSGI+Django方法部署Django程序(下)

@Xavier 好的,不过觉得 其实差不多额

10 年前
回复了 Py站长 创建的主题 » 菜鸟求助

http://www.taiv5.com/search?q=Django%20bulk%20insert

Django 1.4 provides a bulk_create() method on the QuerySet object, see:

https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.bulk_create https://docs.djangoproject.com/en/dev/releases/1.4/ https://code.djangoproject.com/ticket/7596

10 年前
回复了 Py站长 创建的主题 » apache + wsgi + django时Process问题

https://groups.google.com/forum/#!topic/modwsgi/NMgrti4o9Bw

10 年前
回复了 Py站长 创建的主题 » apache + wsgi + django时Process问题

总之,不要混合使用

10 年前
回复了 Py站长 创建的主题 » apache + wsgi + django时Process问题

Using the multiprocessing module within mod_wsgi is a really bad idea. This is because it is an embedded system where Apache and mod_wsgi manage processes. Once you start using multiprocessing module which tries to do its own process management, then it could potentially interfere with the operation of Apache/mod_wsgi in unexpected ways. For example, taking your example and changing it not to be dependent on web.py I get:

import multiprocessing
import os

def x(y):
  print os.getpid(), 'x', y
  return y

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    print 'create pool'
    pool = multiprocessing.Pool(processes=1)
    print 'map call'
    result = pool.map(x, [1])
    print os.getpid(), 'doit', result

    return [output]

If I fire off a request to this it appears to work correctly, returning me hello world string and log the appropriate messages.

[Tue May 03 09:40:36 2011] [info] [client 127.0.0.1] mod_wsgi
(pid=32752, process='hello-1',
application='hello-1.example.com|/mptest.wsgi'): Loading WSGI script
'/Library/WebServer/Sites/hello-1/htdocs/mptest.wsgi'.
[Tue May 03 09:40:36 2011] [error] create pool
[Tue May 03 09:40:36 2011] [error] map call
[Tue May 03 09:40:36 2011] [error] 32753 x 1
[Tue May 03 09:40:36 2011] [error] 32752 doit [1]

However, the process then appears to receive a signal from somewhere causing it to shutdown:

[Tue May 03 09:40:36 2011] [info] mod_wsgi (pid=32752): Shutdown
requested 'hello-1'.
[Tue May 03 09:40:41 2011] [info] mod_wsgi (pid=32752): Aborting
process 'hello-1'.

The multiprocessing module does issue signals, so it may be the source of this.

One thought was that this may be occurring when the pool is destroyed at the end of the function call, so I moved the creation of pool to module scope.

import multiprocessing
import os

print 'create pool'
pool = multiprocessing.Pool(processes=1)

def x(y):
  print os.getpid(), 'x', y
  return y

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    print 'map call'
    result = pool.map(x, [1])
    print os.getpid(), 'doit', result

    return [output]

This though will not even run:

[Tue May 03 09:47:31 2011] [info] [client 127.0.0.1] mod_wsgi
(pid=32893, process='hello-1',
application='hello-1.example.com|/mptest.wsgi'): Loading WSGI script
'/Library/WebServer/Sites/hello-1/htdocs/mptest.wsgi'.
[Tue May 03 09:47:31 2011] [error] create pool
[Tue May 03 09:47:31 2011] [error] map call
[Tue May 03 09:47:31 2011] [error] Process PoolWorker-1:
[Tue May 03 09:47:31 2011] [error] Traceback (most recent call last):
[Tue May 03 09:47:31 2011] [error]   File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/process.py",
line 231, in _bootstrap
[Tue May 03 09:47:31 2011] [error]     self.run()
[Tue May 03 09:47:31 2011] [error]   File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/process.py",
line 88, in run
[Tue May 03 09:47:31 2011] [error]     self._target(*self._args, **self._kwargs)
[Tue May 03 09:47:31 2011] [error]   File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/pool.py",
line 57, in worker
[Tue May 03 09:47:31 2011] [error]     task = get()
[Tue May 03 09:47:31 2011] [error]   File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/queues.py",
line 339, in get
[Tue May 03 09:47:31 2011] [error]     return recv()
[Tue May 03 09:47:31 2011] [error] AttributeError: 'module' object has
no attribute 'x'

The browser also then hangs at that point.

Part of the issue here may be that WSGI script files are not really standard Python modules in that the basename of the WSGI script file doesn't match a module in sys.modules. If the multiprocessing module tries to do magic stuff with imports to find original code to execute in sub process it isn't going to work.

Specifically, may be related to:

http://code.google.com/p/modwsgi/wiki/IssuesWithPickleModule

If I attempt to move x() into being a nested function as:

import multiprocessing
import os

print 'create pool'
pool = multiprocessing.Pool(processes=1)

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    def x(y):
      print os.getpid(), 'x', y
      return y

    print 'map call'
    result = pool.map(x, [1])
    print os.getpid(), 'doit', result

    return [output]

Then one does get pickle errors, albeit for a different reason:

[Tue May 03 09:52:59 2011] [info] [client 127.0.0.1] mod_wsgi
(pid=33010, process='hello-1',
application='hello-1.example.com|/mptest.wsgi'): Loading WSGI script
'/Library/WebServer/Sites/hello-1/htdocs/mptest.wsgi'.
[Tue May 03 09:52:59 2011] [error] create pool
[Tue May 03 09:52:59 2011] [error] map call
[Tue May 03 09:52:59 2011] [error] Exception in thread Thread-1:
[Tue May 03 09:52:59 2011] [error] Traceback (most recent call last):
[Tue May 03 09:52:59 2011] [error]   File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py",
line 522, in __bootstrap_inner
[Tue May 03 09:52:59 2011] [error]     self.run()
[Tue May 03 09:52:59 2011] [error]   File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/threading.py",
line 477, in run
[Tue May 03 09:52:59 2011] [error]     self.__target(*self.__args,
**self.__kwargs)
[Tue May 03 09:52:59 2011] [error]   File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/multiprocessing/pool.py",
line 225, in _handle_tasks
[Tue May 03 09:52:59 2011] [error]     put(task)
[Tue May 03 09:52:59 2011] [error] PicklingError: Can't pickle <type
'function'>: attribute lookup __builtin__.function failed

So, it is doing pickling in some form, which isn't going to work for stuff in WSGI script file.

If you really want to pursue this, then suggest you move this code outside of the WSGI script file and put it in a standard module on the Python module search path you have set up for application.

Overall though, I would recommend against using multiprocessing module from inside of mod_wsgi.

Graham

10 年前
回复了 Py站长 创建的主题 » Django 1.6.5 为什么登录后报错

看看这个http://stackoverflow.com/questions/6295598/django-admin-nonetype-object-has-no-attribute-rindex

可以试下 http://www.taiv5.com/search?q=%27bool%27%20object%20has%20no%20attribute%20%27rindex%27%20%20/admin/ 这个来搜索答案 哦

10 年前
回复了 Py站长 创建的主题 » 问个Django book2.0里 包装视图函数 的问题
url(r'^view4/(?P<x1>\d{2})/(?P<x2>\d{2}/$'

def my_view4(request, x1= None, x2= None):
10 年前
回复了 Py站长 创建的主题 » 如何将两个关联表(对象)的数据结合到一起?

你不要使用会抛 DoesNotExist 的函数嘛 就可以了

更好的做法是一次性从数据库里抓数据出来(用foreigner key),不要用For循环多次从数据库里抓

10 年前
回复了 Py站长 创建的主题 » 新手求助:为什么login_required不生效

@求学者 不应该啊

10 年前
回复了 Py站长 创建的主题 » 新手求助:为什么login_required不生效

你在settings.py里设置一下

https://docs.djangoproject.com/en/dev/ref/settings/#login-url

10 年前
回复了 Py站长 创建的主题 » 【求助】Django初学者,遇到的DJANGO_SETTINGS_MODULE问题

可能路径 有些问题,python manage.py runserver 0.0.0.0:8000 没找到配置

http://osdir.com/ml/DjangoUsers/2009-05/msg00615.html

10 年前
回复了 Py站长 创建的主题 » 【求助】Django初学者,遇到的DJANGO_SETTINGS_MODULE问题

你在你的manager.py里写了

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

了吗 http://stackoverflow.com/questions/7479493/django-settings-module-is-undefined

10 年前
回复了 Py站长 创建的主题 » 用 Django 写网站怎样实现收藏功能?

@yjiehn 他这个是做关注图片的,没有关注 用户

10 年前
回复了 Py站长 创建的主题 » 请教Django REST framework的一些问题

@codingchan 赞的

10 年前
回复了 Py站长 创建的主题 » 求解:DJANGO 指定 oracle schema
class Meta:
    db_table = u'"SCHEMA"."TABLE_NAME"'     # Notice the quoting needed
10 年前
回复了 Py站长 创建的主题 » 请教Django REST framework的一些问题

@codingchan 可以将 total、errorcode 放到 data 里面吗

10 年前
回复了 Py站长 创建的主题 » 请教Django REST framework的一些问题

http://www.django-rest-framework.org/

正如楼上所说,你要的返回是特殊定制,与DRF定义的不一样,也就是说协议不一样。我的理解是,如果你用了DRF,你就必须接受它的协议 。

10 年前
回复了 Py站长 创建的主题 » 新人求教

admin 最好不要大改动吧,你有特殊需求自己特殊做一个简单的就行,

嗯,你可以试一下建在这个目录 下试试,你这个统计是比较通用的

10 年前
回复了 Py站长 创建的主题 » 用 Django 写网站怎样实现收藏功能?

view, 的话,比如,你关注图片的时候,请求时就加一条数据库记录呗

这里有一篇 讲 context的: http://www.cnblogs.com/amghost/p/3572136.html

另外,如果你只是要添加Google统计,直接放 js代码不就好了,

你的定义是 website.context_processors.google_analytics

说明文件名是 context_processors.py 函数名是 google_analytics, 应该放在 你的项目可以找到的目录的 website 目录下

学习了

mark

10 年前
回复了 Py站长 创建的主题 » 用 Django 写网站怎样实现收藏功能?

收藏用户的功能和本社区的关注功能很相似,可以做成以下方式

CREATE TABLE `conanvex_attention` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `user_id` INT(11) NOT NULL,
    `type_id` INT(11) NOT NULL,
    `attention_time` DATETIME NULL DEFAULT NULL,
    `type` INT(11) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX `conanvex_attention_fbfc09f1` (`user_id`)
)

假设用户A要关注用户B,

id是正增长的,user_id代表想要关注别人的用户A,type_id表示要被关注的用户B,Type表示关注类型(版块关注,用户关注,主题关注)

你可以以类似的方法来做,你有两种关注类型,一个是关注用户,一个是关注图片

10 年前
回复了 Py站长 创建的主题 » 原创:基于Google的搜索工具 - Taiv5.com 搜索公测 (太V5)

:)

10 年前
回复了 Py站长 创建的主题 » 原创:基于Google的搜索工具 - Taiv5.com 搜索公测 (太V5)

目前不会出现返回为空 或者 返回乱码的问题