In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Use the module queue queue to control access to global variables
The suprocess creation child process generates multiple shell
This script can be used to judge the network connectivity of each device during the network splicing transformation. The ip address and device name are read from the enterprise configuration library. Use the queue to control variable reading. Ping quickly within 2 seconds.
#! / usr/bin/python#-*- coding: utf-8-*-from threading import Threadimport subprocessfrom Queueimport Queueimport pymysqlnum_threads=10q=Queue () def pingme (iMagol queue): while True: ip=queue.get () ret=subprocess.call ('ping-c 1% s'% ip [0], shell=True,stdout=open ('/ dev/null','w'), stderr=subprocess.STDOUT) # [accept variable string as command, ping sends an ICMP request And redirect standard output to / dev/null, which is equivalent to discarding, and redirect standard error output to standard output. This statement returns the ping value, that is, the python program first creates the shell process, the shell creates the ping process, the ping process runs the return value is waiting for the shell, and the shell returns the value to the python program wait, which is 0.] If ret==0: print'% s is support'% (ip [1], ip [0]) elif ret==1: print'% s is down...'% (ip [1], ip [0]) queue.task_done () # start num_threads threads for i in range (num_threads): t=Thread (target=pingme,args= (I) Q) # Multithreading calls t.setDaemon (True) # sets the daemon thread t.start () db= pymysql.connect (host= "10.50.99.247", user= "network", passwd= "xxxx", port=3306, db= "network", charset='utf8') cursor = db.cursor () cursor.execute ("select ipadd" Name from net_dev where `group`like 'xxx%' ") data = cursor.fetchall () for i in data: q.put (I) # upload list q.join () Print 'finish' ~
Batch test script
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.