首先來分析下你上面的需求需要幾個celery服務
主線程是必須的,所以需要線程main,
因為group2是在group1后執(zhí)行的,所以group1和group2應該是同步方法,執(zhí)行在同一線程;又因為他們需要對主線程異步,所以他們應該是執(zhí)行在一個celery中的。
所以最終的結構應該大致如下:
大致實現(xiàn):
@app.task()
def group1():
return group([add.s(2, 2), add.s(4, 4),])
@app.task()
def group2():
return group([add.s(2, 2), add.s(4, 4),])
@app.task()
def celery3():
result = group1.delay()
# sync group1
result.collect()
group2.delay()
# main thread
celery3.delay()import random
import datetime
from apscheduler.schedulers.background import BackgroundScheduler
scheduler = BackgroundScheduler()
def yourfunc():
print(datetime.datetime.now().strftime('%Y-%m-%d %X'))
def myfunc():
scheduler.remove_job('my_job_id')
yourfunc()
t = random.randint(1,5) # 1~5秒隨機
scheduler.add_job(myfunc, 'interval', seconds=t, id='my_job_id') # seconds可以換成minutes 隨機個60~200分鐘的估計就滿足你的需求了吧
scheduler.add_job(myfunc, 'interval', seconds=1, id='my_job_id')
scheduler.start()先回答題主代碼中的2個問題:
import引入的是包(package),而不是文件夾,Python中如果一個文件夾內存在__init__.py文件時,這個文件夾會被當成是一個包,而非普通的文件夾。sys.path.append的意思是將這個路徑添加到Python解釋器的查詢路徑之中,可以認為是另一種import,但這種方式不如上一種方式來的直接。綜上,建議樓主為每個文件夾添加__init__.py文件,有時間再仔細閱讀一遍基礎文檔。
找到答案了
重新安裝
1、卸載 pip uninstall Pillow-2.3.0
2、安裝 pip install Pillow(沒指定版本,默認最新的 Pillow-4.3.0)
must be str, not <class 'bytes'>
import requests
r = requests.get(url1) # 你第一次的url
headers = {
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding':'gzip, deflate, sdch',
'Accept-Language':'zh-CN,zh;q=0.8',
'Connection':'keep-alive',
'Cache-Control':'no-cache',
'Content-Length':'6',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Host':'www.mm131.com',
'Pragma':'no-cache',
'Origin':'http://www.mm131.com/xinggan/',
'Upgrade-Insecure-Requests':'1',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'X-Requested-With':'XMLHttpRequest'
} # headers的例子,看你的post的headers
headers['cookie'] = ';'.join([headers['cookie'], ['='.join(i) for i in r.cookies.items()]])
r = requests.post(url2, headers=headers, data=data) # 你第二次的url關于如何在 linux 上創(chuàng)建虛擬環(huán)境,建議你看這篇文章 http://www.os373.cn/article/1
至于如何讓本地的 pycharm 使用遠程的虛擬 Python 環(huán)境,建議你看這篇文章 http://www.os373.cn/article/100
別問我是誰,我是雷鋒。
這是安全機制使然,很多網(wǎng)站都有類似要求的。
pywin32 只是windows api的封裝, 現(xiàn)在的QQ機器人都是通過模擬瀏覽器WEBQQ的協(xié)議去做的。不過像XX群發(fā)器都是用 windows api做的。 以前我也弄過不少, 簡單點就是控制鼠標坐標,模擬點擊,模擬回車之類的。點擊前需要獲取窗口位置,當前鼠標的像素顏色等,需要一定的邏輯判斷。
因 Queue 容量有限,應采用一邊生產(chǎn)、一邊消費的同時運作模式,以免隊列滿了造成 Queue.put() 堵塞。
下面這個例子,演示如何使用 ping 命令同時檢查多個域名/IP。
# -*- coding: utf-8 -*-
from subprocess import Popen, PIPE
from multiprocessing import Pool, Manager
def ping(host, q):
# ping 發(fā) 4 個包,超時時間為 1 秒。
p = Popen(['ping', '-c', '4', '-W', '1', host], stdout=PIPE, stderr=PIPE)
p.communicate()
q.put([host, p.returncode == 0 and 'good' or 'bad'])
if __name__ == '__main__':
hosts = [
'www.baidu.com',
'www.taobao.com',
'www.bad123host.com',
'1.2.3.4',
]
m = Manager()
q = m.Queue()
p = Pool(3)
for host in hosts:
p.apply_async(ping, (host, q))
p.close()
for i in range(len(hosts)):
item = q.get()
print(f'{i:03d} {item[0]} is {item[1]}')
p.join()函數(shù)發(fā)生嵌套的時候,this 是不會自動傳遞的,除非你手動傳遞,常見的:
var a={
name:"xuxu",
getname:function(){
console.log(this);
var self=this;
var b=function(){
console.log(self);//對象 a
}
b();
console.log(Window);
}
}
a.getname();
當然也可以通過 apply,call 傳遞 this,等你遇到了再去查查,先留個印象;
根據(jù)最后一行錯誤信息
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
搜索一下即可得到結果。
Python26\Lib\site-packages\OpenGL\DLLS 下有 glut32.dllAccording to the link below the problem was with the glut installation rather than pip install. It seems glut files are not part of PyOpenGL or PyOpenGL_accelerate package. You have to download them seperately.
Windows user can use the link below to download glut as mentioned in the given link.
ftp://ftp.sgi.com/opengl/glut/glut3.html.old#windowsLinux Users can just install glut using the following command:
sudo apt-get install freeglut3-dev
大概像這樣:
# data
log = """
[t=123]xyzzda, x=abc
[t=126]sdjljs, x=abc
[t=140]sdsws, x=abc
[t=239]dsjdjs, x=wvu
[t=248]sdsdess, x=wvu
"""
# code
import re
from collections import defaultdict
dic = defaultdict(list)
golden_x, golden_t = None, None
for line in log.split('\n'):
line = line.strip()
if not line:
continue
m = re.match('\[t=(\d+)\](.+), x=(.+)', line)
t, c, x = m.groups()
if x == golden_x:
dic[x].append((c, int(t) - golden_t))
golden_x, golden_t = x, int(t)
for key, ct in dic.items():
print(key+':')
for c, t in ct:
print(c, 't='+str(t))
print()
# results
abc:
sdjljs t=3
sdsws t=14
wvu:
sdsdess t=9
我回答過的問題: Python-QA
web方向django 就是后臺你想做什么?
web方向大部分都是前端和美化工作.. django就那點東西.. 琢磨完了就去看算法..
要不嘗試自己用 wsgi 實現(xiàn)一個框架? 這個比較有挑戰(zhàn)性
iconbitmap()需要的參數(shù)是圖標的地址.
如果你的python.ico文件是放在當前目錄, 直接root.iconbitmap('python.ico')是沒問題的.
如果python.ico文件是放在別的目錄, 比如/home/user/foo/python.ico, 那就用絕對路徑吧, root.iconbitmap('/home/user/foo/python.ico').
總之, 一定要確定你的文件路徑中存在python.ico這個文件.
'Content-Type': "application/json"的,發(fā)送的參數(shù)在playloads里面,用json=postdata
'Content-Type': "application/x-www-form-urlencoded" 的,發(fā)送的參數(shù)在formdata里面,用data=postdata,formrequest和data=postdata規(guī)則似乎是一樣的
找到錯誤原因了,因為執(zhí)行速度太快,還沒加載完第二個窗口就執(zhí)行了switch_to.window操作,所以沒有跳轉成功,加個time.sleep(1)等待一下就好了。還是自己太馬虎,新手一報錯就不知道怎么解決,希望以后吸取經(jīng)驗教訓。
document.addEventListener("DOMContentLoaded", function(event) {
console.log("DOM fully loaded and parsed");
re.compile(r"select.*?from.*?where.*?;", re.S|re.M)?
北大青鳥APTECH成立于1999年。依托北京大學優(yōu)質雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
達內教育集團成立于2002年,是一家由留學海歸創(chuàng)辦的高端職業(yè)教育培訓機構,是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
北大課工場是北京大學校辦產(chǎn)業(yè)為響應國家深化產(chǎn)教融合/校企合作的政策,積極推進“中國制造2025”,實現(xiàn)中華民族偉大復興的升級產(chǎn)業(yè)鏈。利用北京大學優(yōu)質教育資源及背
博為峰,中國職業(yè)人才培訓領域的先行者
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責任公司從事總經(jīng)理職務負責iOS教學及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術, 熟練的跨平臺面向對象開發(fā)經(jīng)驗,技術功底深厚。 授課風格 授課風格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術顧問,美國Dachieve 系統(tǒng)架構師,美國AngelEngineers Inc. 系統(tǒng)架構師。