使用下面的 python 腳本,你可以輕松實(shí)現(xiàn)多開(kāi)
# -*- coding: utf-8 -*-
'''
同時(shí)運(yùn)行多個(gè)進(jìn)程,用法:
python3 xx.py <進(jìn)程數(shù)量> <進(jìn)程啟動(dòng)參數(shù)>
@author: 李毅
'''
import asyncio
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, REMAINDER
async def single(wid, cmd):
p = await asyncio.create_subprocess_exec(*cmd)
print('#{} pid={} 已經(jīng)啟動(dòng)'.format(wid, p.pid))
await p.communicate()
print('#{} pid={}, 代碼={} 已經(jīng)結(jié)束'.format(wid, p.pid, p.returncode))
async def main(loop, args):
if not args.worker or not len(args.cmd):
return
ps = [single(i, args.cmd) for i in range(args.worker)]
return await asyncio.gather(*ps)
if __name__ == '__main__':
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('worker', type=int, help='進(jìn)程數(shù)')
parser.add_argument('cmd', nargs=REMAINDER, help='命令參數(shù),例如: "sleep 30"')
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop, parser.parse_args()))
舉例:同時(shí)開(kāi)啟 10 個(gè) ping -c4 baidu.com 進(jìn)程
python3 a.py 3 ping -c4 baidu.com
輸出如下
PING baidu.com (123.125.115.110) 56(84) bytes of data.
#1 pid=137 已經(jīng)啟動(dòng)
#2 pid=138 已經(jīng)啟動(dòng)
#0 pid=139 已經(jīng)啟動(dòng)
PING baidu.com (220.181.57.216) 56(84) bytes of data.
PING baidu.com (123.125.115.110) 56(84) bytes of data.
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=1 ttl=52 time=38.0 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=1 ttl=55 time=36.3 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=1 ttl=52 time=38.0 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=2 ttl=52 time=37.9 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=2 ttl=55 time=36.2 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=2 ttl=52 time=37.6 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=3 ttl=52 time=37.9 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=3 ttl=55 time=36.1 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=3 ttl=52 time=37.8 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=4 ttl=52 time=37.9 ms
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 37.916/37.955/38.024/0.199 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=4 ttl=55 time=36.1 ms
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 36.113/36.218/36.374/0.254 ms
#1 pid=137, 代碼=0 已經(jīng)結(jié)束
#2 pid=138, 代碼=0 已經(jīng)結(jié)束
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=4 ttl=52 time=37.7 ms
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 37.647/37.818/38.060/0.249 ms
#0 pid=139, 代碼=0 已經(jīng)結(jié)束鑒于谷歌大佬去年好像搞了個(gè)去除水印大法On the Effectiveness of Visible Watermarks。個(gè)人認(rèn)為直接顯式添加水印方式保護(hù)性一般。
不知題主有沒(méi)有考慮用數(shù)字水印。這種水印的好處就是對(duì)原圖影響小,而且不容易被抹去,魯棒性強(qiáng)。
未捕獲的異常,捕獲一下
雖然不建議直接在子組件直接修改父組件的數(shù)據(jù),但是你這個(gè)需求實(shí)現(xiàn)起來(lái)還挺簡(jiǎn)單的
1.
<li v-for="(item,index) in arr" @click=change(age[index])>{{item.name}}{{age[index]}}</li>
改成
<li v-for="(item,index) in arr" @click=change(index)>{{item.name}}{{age[index]}}</li>
2.
change(num){
return num++; //這樣不行
}
改成
change(index) {
this.age.splice(index, 1, this.age[index] + 1)
}
debug一下看看哈,我也好奇。。。強(qiáng)勢(shì)關(guān)注
你else也要return getNum
另外 var num = num ? num : 1 最好寫成 function(ele,box,num = 1){}
pip 不支持 mysql-connector-python 了,編譯安裝
git clone https://github.com/mysql/mysql-connector-python.git
cd mysql-connector-python
python ./setup.py build
python ./setup.py installskip32
本來(lái)這個(gè)界面是監(jiān)聽(tīng)window的滾動(dòng)條,你現(xiàn)在把他放在iframe標(biāo)簽里當(dāng)然不好用了。
你把iframe標(biāo)簽添加id,進(jìn)行監(jiān)聽(tīng)滾動(dòng)條
answer1: JS 中訪問(wèn)對(duì)象屬性有兩種方法
. 運(yùn)算符,其左邊是引用對(duì)象的變量名稱,右邊是屬性名稱(不加引號(hào),加了引號(hào)叫字符串)[] 運(yùn)算符,其左邊是引用對(duì)象的變量名稱(無(wú)引號(hào)),中間是一個(gè)表達(dá)式,其計(jì)算結(jié)果是表示屬性名稱的字符串。字符串本身也是一個(gè)表達(dá)式,所以可以直接給 g["id"],它與 g.id 效果等同上面提到的“名稱”,其實(shí)叫做標(biāo)識(shí)符,在 JS 中,標(biāo)識(shí)符是有約束的,比如 your-name 就不是一個(gè)合法的標(biāo)識(shí)符,但是它卻是一個(gè)合法的屬性名(因?yàn)?JS 的對(duì)象可以看做一個(gè) Hash 表,所有字符串都中以做為鍵,卻屬性名),這種情況下需要引用屬性,必須使用 [] 運(yùn)算符。比如 o.your-name 就是錯(cuò)誤的,而 o["your-name"] 才是正確。
o.your-name被會(huì)解釋器解釋為o.your - name,是一個(gè)減法表達(dá)式。
answer2:根據(jù)上述原因,g.id.name 本身是一個(gè)合法的表達(dá)式,可以取到其值 1。但是我理解你這里是是想實(shí)現(xiàn)類似 lodash 中 _.get() 函數(shù)的功能,即給定一個(gè)字符串表示屬性路徑,要獲取其值,那么可以分解路徑,再通過(guò)循環(huán)來(lái)獲取值
function get(obj, attrPath) {
const segments = attrPath.split(".");
let current = obj;
for (let i = 0; i < segments.length; i++) {
current = current[segments[i]];
// 容錯(cuò)處理,如果某一步取值為 null 或 undefined
// 就不可能再繼續(xù)下去,直接返回該值即可。
// 也可以根據(jù)業(yè)務(wù)邏輯需要在這里拋出異常
if (current === void 0 || current === null) {
return current;
}
}
return current;
}
使用
get(g, "id.name")cannot read property 'length' of undefined
cannot read property 'length' of undefined
cannot read property 'length' of undefined
不是不能識(shí)別length,是不能讀取undefined.length。所以是你要讀取的length的目標(biāo)對(duì)象本身不存在(或值為空)!
問(wèn)題在format函數(shù)上,如果沒(méi)有指定小數(shù)點(diǎn)后面的精度,只用f,默認(rèn)是小數(shù)點(diǎn)后6位
$config = [
//others
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
];
],
//others
]
class yii\base\Application extends yii\base\Module
class yii\base\Module extends yii\di\ServiceLocator
class yii\di\ServiceLocator extends yii\base\Component
class yii\base\Component extends yii\base\Object
public function __construct($config = [])
{
Yii::$app = $this;
//將\yii\base\Application中的所有的屬性和方法交給Yii::$app->loadedModules數(shù)組中
static::setInstance($this);
$this->state = self::STATE_BEGIN;
//加載配置文件的框架信息 如:設(shè)置別名,設(shè)置框架路徑等等最為重要的是給加載默認(rèn)組件
$this->preInit($config);
//加載配置文件中的異常組件
$this->registerErrorHandler($config);
// 調(diào)用父類的 __construct。
// 由于Component類并沒(méi)有__construct函數(shù)
// 這里實(shí)際調(diào)用的是 `yii\base\Object__construct($config)`
Component::__construct($config);
}
Component::__construct($config) 會(huì)調(diào)用 yii\base\Object::__construct() 方法public function __construct($config = [])
{
if (!empty($config)) {
// 將配置文件里面的所有配置信息賦值給Object。
// 由于Object是大部分類的基類,
// 實(shí)際上也就是有配置信息賦值給了yii\web\Application的對(duì)象
Yii::configure($this, $config);
}
$this->init();
}
'components' => [ 'log' => [...]] 從哪來(lái),若不關(guān)心可以直接看 第二步。$this->preInit($config);,即 yii\base\Application::preInit(&$config)
public function preInit(&$config)
{
//others...
// merge core components with custom components
// 合并核心組件和自定義組件
foreach ($this->coreComponents() as $id => $component) {
if (!isset($config['components'][$id])) {
// 若自定義組件中沒(méi)有設(shè)置該核心組件配置信息,直接使用核心組件默認(rèn)配置
$config['components'][$id] = $component;
} elseif (is_array($config['components'][$id]) && !isset($config['components'][$id]['class'])) {
// 若自定義組件有設(shè)置該核心組件配置信息,但是沒(méi)有設(shè)置 'class'屬性,則添加該class屬性
$config['components'][$id]['class'] = $component['class'];
}
}
}
/**
* Returns the configuration of core application components.
* 返回核心應(yīng)用組件的配置
* @see set()
*/
public function coreComponents()
{
return [
// 日志分配器組件
'log' => ['class' => 'yii\log\Dispatcher'],
//others...
];
}
$this->preInit($config);, 我們得到的 $config
$config = [
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
];
],
'components' => [
'log' => [
'class' => 'yii\\log\\Dispatcher',
],
//others...
]
//others...
]
'components' => [ 'log' => [...]] 從哪來(lái)yii\base\Object::__construct($config = []) 中的 Yii::configure($this, $config);
public static function configure($object, $properties)
{
// 只是遍歷配置信息,賦值給當(dāng)前對(duì)象
foreach ($properties as $name => $value) {
$object->$name = $value;
}
return $object;
}
yii\base\Object::__set($name, $value)
/**
* 為實(shí)例不存在的屬性賦值時(shí)調(diào)用
*
* Do not call this method directly as it is a PHP magic method that
* will be implicitly called when executing `$object->property = $value;`.
* 這個(gè)是PHP的魔術(shù)方法,會(huì)在執(zhí)行 `$object->property = $value;` 的時(shí)候自動(dòng)調(diào)用。
*/
public function __set($name, $value)
{
// setter函數(shù)的函數(shù)名
// 由于php中方法名稱不區(qū)分大小寫,所以setproperty() 等價(jià)于 setProperty()
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
// 調(diào)用setter函數(shù)
$this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) {
// 如果只有g(shù)etter沒(méi)有setter 則為只讀屬性
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
} else {
throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}
}
當(dāng)前情景下的 $object 我們可以認(rèn)為是 yii\base\Application 的對(duì)象 $app
$app->modules = [
'debug' => [
'class' => 'yii\debug\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
];
]
這里會(huì)調(diào)用 yii\base\Module::setModules($modules) 方法
public function setModules($modules)
{
foreach ($modules as $id => $module) {
$this->_modules[$id] = $module;
}
}
這樣便有了問(wèn)題中的
private "_modules" (yiibasemodule)=>
array (size=3)
'backend' =>....
'debug' =>...
'gii'=>...
$app->components = [
'log' => [
'class' => 'yii\\log\\Dispatcher',
],
]
yii\di\ServiceLocator::setComponents($components) 方法public function setComponents($components)
{
foreach ($components as $id => $component) {
$this->set($id, $component);
}
}
public function set($id, $definition)
{
// others ...
if (is_object($definition) || is_callable($definition, true)) {
// an object, a class name, or a PHP callable
$this->_definitions[$id] = $definition;
} elseif (is_array($definition)) {
// 定義如果是個(gè)數(shù)組,要確保數(shù)組中具有 class 元素
// a configuration array
if (isset($definition['class'])) {
// 定義的過(guò)程,只是寫入了 $_definitions 數(shù)組
$this->_definitions[$id] = $definition;
} else {
throw new InvalidConfigException("The configuration for the \"$id\" component must contain a \"class\" element.");
}
} else {
throw new InvalidConfigException("Unexpected configuration type for the \"$id\" component: " . gettype($definition));
}
}
這樣便有了問(wèn)題中的
private "_definitions"(yiidiservicelocator)=>
array (size=7)
...
'log'=>...
...建議全部轉(zhuǎn)為utf8mb4編碼。
ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;是不是沒(méi)有權(quán)限寫呀
解決了 ,,換了一種方式,吧public的ui-view 放到 每一個(gè)小頁(yè)面的模板里面去了 這樣簡(jiǎn)單多了
別用偽類,換成單獨(dú)元素
點(diǎn)擊全選的時(shí)候遍歷一遍復(fù)選框狀態(tài),然后統(tǒng)一改變所有狀態(tài),簡(jiǎn)單又粗暴
北大青鳥(niǎo)APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
北大課工場(chǎng)是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國(guó)家深化產(chǎn)教融合/校企合作的政策,積極推進(jìn)“中國(guó)制造2025”,實(shí)現(xiàn)中華民族偉大復(fù)興的升級(jí)產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國(guó)職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開(kāi)發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_(kāi)發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開(kāi)發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開(kāi)發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開(kāi)發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。