顯示具有 python 標籤的文章。 顯示所有文章
顯示具有 python 標籤的文章。 顯示所有文章

星期三, 7月 24, 2019

How to check and modify pids.max of user

1. find out the cgroup of the user

#echo $$|xargs -I '$' cat '/proc/$/cgroup'


/user.slice/user-1000.slice is the cgroup of the user

2. check the pids.max (TasksMax) setting for the user
(1) method 1:
#cgget -a /user.slice/user-1000.slice


(2) method 2:
#cat /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids*

3. modify the pids.max
# systemctl set-property user-1000.slice TasksMax=512

4. verify (using python script)

import time
import threading

def worker():
    while True:
        time.sleep(1000)
        

threads = []
num_worker_threads = 19000
for i in range(num_worker_threads):
    t = threading.Thread(target=worker)
    try:
        t.start()
        threads.append(t)
        print(i)
    except:
        print("EX")
        time.sleep(2000)

for t in threads:
    t.join()
python script:
https://zhuanlan.zhihu.com/p/29192624

cgroup information:
https://access.redhat.com/documentation/zh-tw/red_hat_enterprise_linux/6/html/resource_management_guide/sec-obtaining_information_about_control_groups

xargs:
https://superuser.com/questions/401614/inserting-string-from-xargs-into-another-string




星期二, 12月 19, 2017

如何使用WAS下的scriptLibraries來簡化wsadmin操作

WAS下的scriptLibraries下有一些IBM提供給管理者簡化wsadmin 命令的Library (提供額外的命令來包裝原先複雜的wsadmin 命令), 讓管理可以方便使用。

其使用方法如下﹕(以設定WebContainer thread Pool 為例)

(1)./wsadmin.sh -lang jython -username admin_id -password admin_password

(2)進入wsadmin介面後, 使用execfile來載入擴充的Libraries。
wsadmin>execfile('<WAS-install-root>/scriptLibraries/servers/V70/AdminServerManagement.py')

(3)之後便能使用擴充的指令(至於有哪些指令, 可以自行參考那個.py 檔案的內容說明)
以AdminServerManagement.py 來說其設定Thread Pool的擴充指令為:configureThreadPool
=========================
  Ex40: configureThreadPool
# Example 40: Configure thread pool
def configureThreadPool(nodeName, serverName, parentType, tpName, maxSize, minSize, inactivityTimeout, otherAttrList=[], failonerror=AdminUtilities._BLANK_):
try:
        #--------------------------------------------------------------------
        # Configuring ThreadPool
        #--------------------------------------------------------------------
        print "---------------------------------------------------------------"
        print " AdminServerManagement:  Configuring ThreadPool"
        print " nodeName:               "+nodeName
        print " serverName:             "+serverName
        print " parentType:             "+parentType
        print " threadPoolName:         "+tpName
        print " maximumSize:            %s" % (maxSize)
        print " minimumSize:            %s" % (minSize)
        print " inactivityTimeout:      %s" % (inactivityTimeout)
===========================

(4)依上面說明, 其正確指令可寫成:
wsadmin>
configureThreadPool("loveNode02","base03","ThreadPoolManager","WebContainer","200","100","60000")

(5)其輸出結果如下﹕

---------------------------------------------------------------
 AdminServerManagement:  Configuring ThreadPool
 nodeName:               loveNode02
 serverName:             base03
 parentType:             ThreadPoolManager
 threadPoolName:         WebContainer
 maximumSize:            200
 minimumSize:            100
 inactivityTimeout:      60000
 Optional Attributes:
     otherAttributeList  []
 Usage: AdminServerManagement.configureThreadPool("loveNode02", "base03", "ThreadPoolManager", "WebContainer", "'200'", "'100'", "'60000'")
 Return: If the command is successful, a value of 1 is returned.
---------------------------------------------------------------


[customProperties []]
[inactivityTimeout 60000]
[isGrowable false]
[maximumSize 200]
[minimumSize 100]
[name WebContainer]
1

(6)若要把這二個步驟合成一個, 就自行寫個abc.py, 其內容如下﹕

execfile('<WAS-install-root>/scriptLibraries/servers/V70/AdminServerManagement.py')
configureThreadPool("loveNode02","base03","ThreadPoolManager","WebContainer","200","100","60000")

(7)最後要執行時就只要去指定abc.py 即可:
./wsadmin.sh -f abc.py












星期三, 3月 01, 2017

Can't install OpenCV3 on Anaconda3 python3.6

Can't install OpenCV3 on Anaconda3 python3.6


while opencv3 yields no results
$ conda search opencv3
NoPackagesFoundError: Package missing in current osx-64 channels: 
  - opencv3
Installing menpo opencv3 build gives following conflict:
$ conda install -c menpo opencv3
Fetching package metadata ...........
Solving package specifications: .
UnsatisfiableError: The following specifications were found to be in conflict:
  - opencv3 -> python 2.7* -> openssl 1.0.1*
  - python 3.6*
Use "conda info <package>" to see the dependencies for each package.

Answer:
Since you are using a newer version of python3, you would probably have to build opencv from the recipe yourself, which is available at https://github.com/conda-forge/opencv-feedstock
Another option is to have the specific version of python3 in your new environment by creating it like this:
(root) osx:Downloads nwani$ conda list | grep python 
python                    3.6.0                         0 
(root) osx:Downloads nwani$ conda create -yn opencvtest python=3.5.2 
(root) osx:Downloads nwani$ source activate opencvtest 
(opencvtest) osx:Downloads nwani$ conda list | grep python 
python                    3.5.2                         0
The version 3.1.0 builds of opencv are available on the conda-forge channel:
(root) osx:Downloads nwani$ conda search -c conda-forge --spec 'opencv=3*' 
Fetching package metadata ......... 
opencv                       3.1.0               np110py27_0  conda-forge     
                             3.1.0               np110py34_0  conda-forge     
                             3.1.0               np110py35_0  conda-forge     
                             3.1.0               np111py27_0  conda-forge     
                             3.1.0               np111py34_0  conda-forge     
                             3.1.0               np111py35_0  conda-forge     
                             3.1.0               np110py27_1  conda-forge     
                             3.1.0               np110py34_1  conda-forge     
                             3.1.0               np110py35_1  conda-forge     
                             3.1.0               np111py27_1  conda-forge     
                             3.1.0               np111py34_1  conda-forge     
                             3.1.0               np111py35_1  conda-forge
You can install it like this (Unix Like platform):
(opencvtest) osx:Downloads nwani$ conda install -y -c conda-forge opencv 
(opencvtest) osx:Downloads nwani$ conda list | grep -e python -e opencv
# packages in environment at /Users/nwani/Downloads/m3/envs/opencvtest:
opencv                    3.1.0               np111py35_1    conda-forge
python                    3.5.2                         0  
For Windows platform:
conda insatll -c https://conda.anaconda.org/menpo opencv3
You may also add channel menpo in the Anaconda Navigator and then you can install
the opencv3 via Anaconda Navigator (GUI) easily.
=======================================================
You may like to add the "menpo" channel permanently by: conda config --add channels menpo And then opencv can be installed by: conda install opencv(or opencv3)
========================================================

ANACONDA PACKAGE LIST

星期一, 2月 20, 2017

Tools to download videos from websites - youtube-dl

Tools to download videos from websites - youtube-dl



very powerful and easy to use

# Download YouTube playlist videos in separate directory indexed by video order in a playlist
$ youtube-dl -o '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' https://www.youtube.com/playlist?list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re

#Download single YouTube video
$youtube-dl -f mp4 https://www.youtube.com/watch?v=Ezf_JiMilP4&list=FLJmUih3PSbm6HY73nBOjxBg&index=1 -o '%(title)s.%(ext)s'


說明文件﹕
https://github.com/rg3/youtube-dl/blob/master/README.md#readme

***
在一些舊版本的Linux上執行會有error, 懷疑是python相關的library版本和新版的youtube-dl不合造成,在新版本的Linux上執行都可以順利完成。

***