正如webpack的wiki所说,可以使用分析工具来优化构建性能:
来自:https://github.com/webpack/docs/wiki/build-performance#hints-from-build-stats
来自构建统计数据的提示
有一个分析工具可以显示您的构建,并提供一些提示如何优化构建大小和构建性能.
您可以通过运行webpack --profile --json> stats.json来生成所需的JSON文件
我生成stats文件(可在此处)将其上传到webpack的analize工具
,在Hints选项卡下我告诉我使用prefetchPlugin:
来自:http://webpack.github.io/analyse/#hints
长模块构建链
使用预取来提高构建性能.从链的中间预取模块.
我从里面挖出网页,找到prefechPlugin上唯一可用的文档是这样的:
来自:https://webpack.js.org/plugins/prefetch-plugin/
PrefetchPlugin
new webpack.PrefetchPlugin([context], request)对正常模块的请求,即使在需要之前解析和构建也是如此.这可以提高性能.尝试首先分析构建以确定聪明的预取点.
我真的很感激一些例子
请帮助我将这个问题作为下一个想要使用prefechPlugin和Analyze工具的开发人员的宝贵资源.谢谢.
在什么情况下我想用一个而不是另一个?
有什么区别:
>>> import inspect
>>> print(inspect.getouterframes(inspect.currentframe()))
[(<frame object at 0x8fc262c>, '<stdin>', 1, '<module>', None, None)]
Run Code Online (Sandbox Code Playgroud)
和:
>>> import traceback
>>> traceback.extract_stack()
[('<stdin>', 1, '<module>', None)]
Run Code Online (Sandbox Code Playgroud)
更新:
另一个:
>>> import sys
>>> print(sys._getframe().f_trace,sys._getframe().f_code)
(None, <code object <module> at 0x8682a88, file "<stdin>", line 1>)
Run Code Online (Sandbox Code Playgroud)
我不明白这里的细微差别:
更新2,问题问题后的一段时间,但非常相关
我有一个用node.js express开发的移动应用程序后端.我尝试将其部署为lambda服务.为此,我创建了一个无服务器框架项目(https://github.com/serverless).之前我通过启动快速后端应用程序在本地测试了移动应用程序.现在我找不到一种方法来在没有本地后端的情况下在本地测试我的移动应用程序.jaws run命令只在我调用它时运行.
是否有任何方法可以将lambda函数作为Web服务启动?或者是否有无服务器框架的替代方案?
python amazon-web-services node.js aws-lambda serverless-framework
我正在尝试将TokenAuthentication与我的一个视图一起使用.如https://www.django-rest-framework.org/api-guide/authentication/中所述,我将登录时收到的令牌添加为我发送的请求中称为"授权"的HTTP头.
问题是在我的单元测试中,身份验证失败了.查看TokenAuthentication类,我看到正在检查的标头是'HTTP_AUTHORIZATION'而不是'授权'
我正在使用的视图:
class DeviceCreate(generics.CreateAPIView):
model = Device
serializer_class = DeviceSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,)
Run Code Online (Sandbox Code Playgroud)
将标题更改为"HTTP_AUTHORIZATION"似乎有效,但感觉不对.
我错过了什么吗?
django authorization django-rest-framework http-token-authentication
我正在按照本教程将Graphene与Django一起使用,一切都进行得很顺利,直到我到达了与 Django Rest Framework的集成部分。
本节说您可以通过创建序列化器克隆来将DRF序列化器与Graphene重用,但它没有说明如何处理此类克隆以将DRF序列化器与Graphene重用。
这些是我的序列化程序和克隆:
from rest_framework import serializers
from graphene_django.rest_framework.mutation import SerializerMutation
from GeneralApp.models import Airport
from ReservationsManagerApp.serializers import ReservationSerializer
from ReservationsManagerApp.models import ReservationComponent, ReservationHotel, ReservationRoundtrip, ReservationTransfer, ReservationTour, ReservationService, Hotel
class ReservationMutation(SerializerMutation):
class Meta:
serializer_class = ReservationSerializer
class ReservationComponentGraphSerializer(serializers.ModelSerializer):
component = serializers.SerializerMethodField()
class Meta:
model = ReservationComponent
fields = ('id', 'reservation', 'dertour_bk', 'day', 'content_type', 'object_id', 'comment', 'is_invoiced', 'component')
def get_component(self, …Run Code Online (Sandbox Code Playgroud) {
"errorMessage": "Unable to import module 'lambda_function':
cannot import name 'etree' from 'lxml' (/var/task/lxml/__init__.py)",
"errorType": "Runtime.ImportModuleError"
}
Run Code Online (Sandbox Code Playgroud)
也试过https://gist.github.com/allen-munsch/ad8faf9c04b72aa8d0808fa8953bc639:
{
"errorMessage": "Unable to import module 'lambda_function':
cannot import name 'etree' from 'lxml'
(/var/task/lxml-4.3.4-py3.6-linux-x86_64.egg/lxml/__init__.py)",
"errorType": "Runtime.ImportModuleError"
}
Run Code Online (Sandbox Code Playgroud)
我Ubuntu 18.04在我的本地机器上运行,并且还尝试在 ec2 实例上使用“Amazon Linux”映像来构建包。
我也试过,在激活的 venv 中:
STATIC_DEPS=true pip3 install lxml --target ./package --upgrade --no-cache-dir
Run Code Online (Sandbox Code Playgroud)
我还尝试根据在运行脚本时打开哪些文件来复制共享对象文件strace:
#! /bin/bash
export Z=$(pwd)/ok-daily-lambda.zip
rm $Z
zip $Z lambda_function.py
zip $Z __init__.py
for dir in $(find venv_here/lib/python3.6/site-packages)
do
if [ -d $dir …Run Code Online (Sandbox Code Playgroud) 我已经设置了一个heroku管道,并且刚刚启用了审核应用程序.它使用与我的登台和制作应用程序相同的代码库,相同的设置文件和所有内容.
当审核应用程序旋转时,它可以连接到创建的数据库并运行迁移.当我尝试在浏览器中连接到应用程序时,我明白了
`TypeError: argument 2 must be a connection, cursor or None` in `psycopg2/_json.py, register_json:139`
Run Code Online (Sandbox Code Playgroud)
堆栈顶部是:
`django.contrib.sites.models._get_site_by_id`.
Run Code Online (Sandbox Code Playgroud)
我在这篇文章的底部附上了错误框架的Opbeat输出.
设置文件已链接.
当我设置DEBUG=True,一切正常.这可能表明一个ALLOWED_HOSTS问题,但是当我设置ALLOWED_HOSTS要'*'与DEBUG=False,它仍然错误?
我的设置有什么问题?这适用于暂存和制作,但不适用于评论应用.
这是我的UserProfile修改
class UserProfile(models.Model):
user = models.OneToOneField(User)
fb_id = models.IntegerField(primary_key=True,null=False,blank=True)
follows = models.ManyToManyField('self', related_name='followed_by', symmetrical=False)
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
Run Code Online (Sandbox Code Playgroud)
尝试删除所有测试用户或其中任何一个用户后,我收到以下错误.
django.db.utils.IntegrityError: update or delete on table "blog_userprofile" violates foreign key constraint "blog_from_userprofile_id_a482ff43f3cdedf_fk_blog_userprofile_id" on table "blog_userprofile_follows"
DETAIL: Key (id)=(4) is still referenced from table "blog_userprofile_follows".
Run Code Online (Sandbox Code Playgroud)
默认情况下级联删除应该是真的,为什么我收到这个,我该如何解决?我正在使用PostgreSQL + Django 1.8
编辑:小先决条件:我primary_key从默认更改为fb_id.并且有重复,因为它没有设置唯一.因此,当我尝试迁移/ makemigrations/syncdb时会引发此错误:
django.db.utils.IntegrityError: could not create unique index "blog_userprofile_fb_id_ce4e6e3086081d4_uniq"
DETAIL: Key (fb_id)=(0) is duplicated.
Run Code Online (Sandbox Code Playgroud)
这就是我试图删除所有测试用户的原因
当我尝试重置所有内容时,我试图恢复默认主键,我收到:
django.db.utils.ProgrammingError: multiple default values specified for column "id" of table "blog_userprofile"
Run Code Online (Sandbox Code Playgroud) 我正在尝试为每个模块及其子模块查找所有丢失的导入语句和错误。
是否有专门的工具可以用于我正在尝试做的事情?
我写的代码,但看起来真的很糟糕,也许这样的东西已经存在?:
import os
def find_missing_imports(walk):
for items in walk:
d = items[0]
f_list = items[1]
for f in f_list:
module = f[:-3]
# posix_path
module_path = d.lstrip('.').replace('/','.').lstrip('.')
try:
__import__(module_path, fromlist=[module])
except IndentationError, e:
#print(f,e)
pass
except NameError, e:
print(d,f,e)
pass
except Exception, e:
print(f,e)
pass
walk = [[root,files] for root,dirs,files in os.walk('.') for fn in files if fn.endswith('.py')]
find_missing_imports(walk)
Run Code Online (Sandbox Code Playgroud)
输出:
.[snip]
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ImageSelectionFrame.py', NameError("name 'wx' is not defined",))
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ItemSpecificsDialog.py', NameError("name 'wx' is not defined",))
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ReturnCorrectWatchTitle.py', NameError("name …Run Code Online (Sandbox Code Playgroud) 我有一个 python 环境(在 Windows 10 上),它使用 OpenCVVideoCapture类连接到多个 USB 摄像头。
据我所知,除了类构造函数/方法device中的参数之外,没有其他方法可以识别 OpenCV 中的特定相机。VideoCaptureopen
问题是设备参数会根据实际连接的摄像头数量和 USB 端口而变化。
我希望能够识别特定的相机并找到其“设备索引”或“相机索引”,无论连接了多少个相机以及连接到哪个 USB 端口。
有人可以建议一种实现该功能的方法吗?python 代码更好,但 C++ 也可以。
python ×8
django ×4
aws-lambda ×2
postgresql ×2
c++ ×1
heroku ×1
inspect ×1
node.js ×1
opencv ×1
optimization ×1
psycopg2 ×1
refactoring ×1
sys ×1
traceback ×1
usb ×1
webpack ×1
windows ×1