Re: why and how to run forever and debug when error in for proc in psutil.process_iter()?

2017-03-26 Thread Ho Yeung Lee
On Sunday, March 26, 2017 at 7:40:20 PM UTC+8, Ho Yeung Lee wrote:
> On Sunday, March 26, 2017 at 7:32:12 PM UTC+8, Ho Yeung Lee wrote:
> > On Sunday, March 26, 2017 at 10:33:51 AM UTC+8, Deborah Swanson wrote:
> > > Someone here can probably help you, but they'll need your Python
> > > version, operating system, and full traceback. They get tired of saying
> > > so. 
> > > 
> > > In this case, the full traceback is needed to see what went wrong and
> > > when (after which statements).
> > > 
> > > 
> > > Ho Yeung Lee wrote, on Saturday, March 25, 2017 1:38 AM
> > > > 
> > > > expect below to run forever and keep running a fixed number 
> > > > of thread in python
> > > > 
> > > > would like to kill tasks when process connect internet except 
> > > > chrome and explorer.exe
> > > > 
> > > > i do this because MalwareBytes can not disconnect these 
> > > > existing trojan when my notebook connect internet
> > > > 
> > > > after run a few minutes, the program stopped, but i have 
> > > > already kept create process, why the whole program end?
> > > > 
> > > > why and how to debug when error in for proc in psutil.process_iter()?
> > > > 
> > > > 
> > > > import os
> > > > import psutil
> > > > import multiprocessing
> > > > import time
> > > > import sys
> > > > 
> > > > def cleantask():
> > > > p = os.popen("netstat -ano")
> > > > while 1:
> > > > line = p.readline()
> > > > if "TCP" in line or "UDP" in line:
> > > > linelist = line.split()
> > > > if len(linelist) > 4:
> > > > if "LISTEN" in str(linelist[3]):
> > > > for proc in psutil.process_iter():
> > > > try:
> > > > if "pop" not in str(proc.name).tolower():
> > > > os.system("taskkill /f /pid 
> > > > "+str(proc._pid))
> > > > except:
> > > > dummy = 1
> > > > #print "Unexpected error:", 
> > > > sys.exc_info()[0]
> > > > #print "Unexpected error:", 
> > > > sys.exc_info()[1]
> > > > if "ESTABLISHED" in str(linelist[3]):
> > > > if "127.0.0.1" not in str(linelist[2]):
> > > > for proc in psutil.process_iter():
> > > > try:
> > > > if str(linelist[4]) in 
> > > > str(proc._pid):
> > > > 
> > > > print(str(linelist[2])+","+str(linelist[4])+","+proc.name)
> > > > if "111.221" not in 
> > > > str(linelist[2]) and "explorer.exe" not in str(proc.name).tolower():
> > > > os.system("taskkill /f 
> > > > /pid "+str(proc._pid))
> > > > except:
> > > > dummy = 1
> > > > #print "Unexpected error:", 
> > > > sys.exc_info()[0]
> > > > #print "Unexpected error:", 
> > > > sys.exc_info()[1]
> > > > print(line)
> > > > if not line: break
> > > > 
> > > > if __name__ == '__main__':
> > > > print("main")
> > > > try:
> > > > numberofrunning = 0
> > > > plist = []
> > > > for ii in range(0,5):  
> > > > p = multiprocessing.Process(target=cleantask(), args=(0,))
> > > > p.start()
> > > > plist.append(p)
> > > > numberofrunning = numberofrunning + 1
> > > > time.sleep(1)
> > > > for pp in plist:
> > > > pp.join()
> > > > if pp.is_alive() == False:
> > > > numberofrunning = numberofrunning - 1
> > > > plist.remove(pp)
> > > > if numberofrunning > 10:
> > > > print "more than 10 process"
> > > > else:
> > > > print("number of process = " + str(numberofrunning))
> > > > if numberofrunning <= 5:
> > > > p = 
> > > > multiprocessing.Process(target=cleantask(), args=(0,))
> > > > p.start()
> > > > plist.append(p)
> > > > numberofrunning = numberofrunning + 1
> > > > time.sleep(1)
> > > > except:
> > > > print "Unexpected error:", sys.exc_info()[0]
> > > > print "Unexpected error:", sys.exc_info()[1]
> > > > -- 
> > > > https://mail.python.org/mailman/listinfo/python-list
> > > >
> > 
> > after window update error, I can not login window and reset system and
> > reinstall every thing
> > 
> > python 2.7.12
> > 
> > there is no error when run, but it end after running a few minutes
> > if commend the forever loop in main
> > 
> > import os
> > import psutil
> > import multiprocessing
> > import time
> > import sys
> > 
> > def cleantask():
> > bufsize = 0
> > f = open("d:\\kill

Re: why and how to run forever and debug when error in for proc in psutil.process_iter()?

2017-03-26 Thread Ho Yeung Lee
On Sunday, March 26, 2017 at 7:32:12 PM UTC+8, Ho Yeung Lee wrote:
> On Sunday, March 26, 2017 at 10:33:51 AM UTC+8, Deborah Swanson wrote:
> > Someone here can probably help you, but they'll need your Python
> > version, operating system, and full traceback. They get tired of saying
> > so. 
> > 
> > In this case, the full traceback is needed to see what went wrong and
> > when (after which statements).
> > 
> > 
> > Ho Yeung Lee wrote, on Saturday, March 25, 2017 1:38 AM
> > > 
> > > expect below to run forever and keep running a fixed number 
> > > of thread in python
> > > 
> > > would like to kill tasks when process connect internet except 
> > > chrome and explorer.exe
> > > 
> > > i do this because MalwareBytes can not disconnect these 
> > > existing trojan when my notebook connect internet
> > > 
> > > after run a few minutes, the program stopped, but i have 
> > > already kept create process, why the whole program end?
> > > 
> > > why and how to debug when error in for proc in psutil.process_iter()?
> > > 
> > > 
> > > import os
> > > import psutil
> > > import multiprocessing
> > > import time
> > > import sys
> > > 
> > > def cleantask():
> > > p = os.popen("netstat -ano")
> > > while 1:
> > > line = p.readline()
> > > if "TCP" in line or "UDP" in line:
> > > linelist = line.split()
> > > if len(linelist) > 4:
> > > if "LISTEN" in str(linelist[3]):
> > > for proc in psutil.process_iter():
> > > try:
> > > if "pop" not in str(proc.name).tolower():
> > > os.system("taskkill /f /pid 
> > > "+str(proc._pid))
> > > except:
> > > dummy = 1
> > > #print "Unexpected error:", 
> > > sys.exc_info()[0]
> > > #print "Unexpected error:", 
> > > sys.exc_info()[1]
> > > if "ESTABLISHED" in str(linelist[3]):
> > > if "127.0.0.1" not in str(linelist[2]):
> > > for proc in psutil.process_iter():
> > > try:
> > > if str(linelist[4]) in 
> > > str(proc._pid):
> > > 
> > > print(str(linelist[2])+","+str(linelist[4])+","+proc.name)
> > > if "111.221" not in 
> > > str(linelist[2]) and "explorer.exe" not in str(proc.name).tolower():
> > > os.system("taskkill /f 
> > > /pid "+str(proc._pid))
> > > except:
> > > dummy = 1
> > > #print "Unexpected error:", 
> > > sys.exc_info()[0]
> > > #print "Unexpected error:", 
> > > sys.exc_info()[1]
> > > print(line)
> > > if not line: break
> > > 
> > > if __name__ == '__main__':
> > > print("main")
> > > try:
> > > numberofrunning = 0
> > > plist = []
> > > for ii in range(0,5):  
> > > p = multiprocessing.Process(target=cleantask(), args=(0,))
> > > p.start()
> > > plist.append(p)
> > > numberofrunning = numberofrunning + 1
> > > time.sleep(1)
> > > for pp in plist:
> > > pp.join()
> > >   if pp.is_alive() == False:
> > > numberofrunning = numberofrunning - 1
> > > plist.remove(pp)
> > > if numberofrunning > 10:
> > > print "more than 10 process"
> > > else:
> > > print("number of process = " + str(numberofrunning))
> > > if numberofrunning <= 5:
> > > p = 
> > > multiprocessing.Process(target=cleantask(), args=(0,))
> > > p.start()
> > > plist.append(p)
> > > numberofrunning = numberofrunning + 1
> > > time.sleep(1)
> > > except:
> > > print "Unexpected error:", sys.exc_info()[0]
> > > print "Unexpected error:", sys.exc_info()[1]
> > > -- 
> > > https://mail.python.org/mailman/listinfo/python-list
> > >
> 
> after window update error, I can not login window and reset system and
> reinstall every thing
> 
> python 2.7.12
> 
> there is no error when run, but it end after running a few minutes
> if commend the forever loop in main
> 
> import os
> import psutil
> import multiprocessing
> import time
> import sys
> 
> def cleantask():
> bufsize = 0
> f = open("d:\\killlist.txt",'a',bufsize)
> p = os.popen("netstat -ano")
> while 1:
> line = p.readline()
> if "TCP" in line or "UDP" in line:
> linelist = line.split()
> if len(linelist) > 4:
> if "LISTEN" in str(linelist[3]):
> for proc in psutil

Re: why and how to run forever and debug when error in for proc in psutil.process_iter()?

2017-03-26 Thread Ho Yeung Lee
On Sunday, March 26, 2017 at 10:33:51 AM UTC+8, Deborah Swanson wrote:
> Someone here can probably help you, but they'll need your Python
> version, operating system, and full traceback. They get tired of saying
> so. 
> 
> In this case, the full traceback is needed to see what went wrong and
> when (after which statements).
> 
> 
> Ho Yeung Lee wrote, on Saturday, March 25, 2017 1:38 AM
> > 
> > expect below to run forever and keep running a fixed number 
> > of thread in python
> > 
> > would like to kill tasks when process connect internet except 
> > chrome and explorer.exe
> > 
> > i do this because MalwareBytes can not disconnect these 
> > existing trojan when my notebook connect internet
> > 
> > after run a few minutes, the program stopped, but i have 
> > already kept create process, why the whole program end?
> > 
> > why and how to debug when error in for proc in psutil.process_iter()?
> > 
> > 
> > import os
> > import psutil
> > import multiprocessing
> > import time
> > import sys
> > 
> > def cleantask():
> > p = os.popen("netstat -ano")
> > while 1:
> > line = p.readline()
> > if "TCP" in line or "UDP" in line:
> > linelist = line.split()
> > if len(linelist) > 4:
> > if "LISTEN" in str(linelist[3]):
> > for proc in psutil.process_iter():
> > try:
> > if "pop" not in str(proc.name).tolower():
> > os.system("taskkill /f /pid 
> > "+str(proc._pid))
> > except:
> > dummy = 1
> > #print "Unexpected error:", 
> > sys.exc_info()[0]
> > #print "Unexpected error:", 
> > sys.exc_info()[1]
> > if "ESTABLISHED" in str(linelist[3]):
> > if "127.0.0.1" not in str(linelist[2]):
> > for proc in psutil.process_iter():
> > try:
> > if str(linelist[4]) in 
> > str(proc._pid):
> > 
> > print(str(linelist[2])+","+str(linelist[4])+","+proc.name)
> > if "111.221" not in 
> > str(linelist[2]) and "explorer.exe" not in str(proc.name).tolower():
> > os.system("taskkill /f 
> > /pid "+str(proc._pid))
> > except:
> > dummy = 1
> > #print "Unexpected error:", 
> > sys.exc_info()[0]
> > #print "Unexpected error:", 
> > sys.exc_info()[1]
> > print(line)
> > if not line: break
> > 
> > if __name__ == '__main__':
> > print("main")
> > try:
> > numberofrunning = 0
> > plist = []
> > for ii in range(0,5):  
> > p = multiprocessing.Process(target=cleantask(), args=(0,))
> > p.start()
> > plist.append(p)
> > numberofrunning = numberofrunning + 1
> > time.sleep(1)
> > for pp in plist:
> > pp.join()
> > if pp.is_alive() == False:
> > numberofrunning = numberofrunning - 1
> > plist.remove(pp)
> > if numberofrunning > 10:
> > print "more than 10 process"
> > else:
> > print("number of process = " + str(numberofrunning))
> > if numberofrunning <= 5:
> > p = 
> > multiprocessing.Process(target=cleantask(), args=(0,))
> > p.start()
> > plist.append(p)
> > numberofrunning = numberofrunning + 1
> > time.sleep(1)
> > except:
> > print "Unexpected error:", sys.exc_info()[0]
> > print "Unexpected error:", sys.exc_info()[1]
> > -- 
> > https://mail.python.org/mailman/listinfo/python-list
> >

after window update error, I can not login window and reset system and
reinstall every thing

python 2.7.12

there is no error when run, but it end after running a few minutes
if commend the forever loop in main

import os
import psutil
import multiprocessing
import time
import sys

def cleantask():
bufsize = 0
f = open("d:\\killlist.txt",'a',bufsize)
p = os.popen("netstat -ano")
while 1:
line = p.readline()
if "TCP" in line or "UDP" in line:
linelist = line.split()
if len(linelist) > 4:
if "LISTEN" in str(linelist[3]):
for proc in psutil.process_iter():
try:
if "pop" in str(proc.name).lower():
os.system("taskkill /f /pid "+str(proc._pid))
#print("here8")

print(str(linelist[2])+","+str(linelist[4])+","+proc.name 

RE: why and how to run forever and debug when error in for proc in psutil.process_iter()?

2017-03-25 Thread Deborah Swanson
Someone here can probably help you, but they'll need your Python
version, operating system, and full traceback. They get tired of saying
so. 

In this case, the full traceback is needed to see what went wrong and
when (after which statements).


Ho Yeung Lee wrote, on Saturday, March 25, 2017 1:38 AM
> 
> expect below to run forever and keep running a fixed number 
> of thread in python
> 
> would like to kill tasks when process connect internet except 
> chrome and explorer.exe
> 
> i do this because MalwareBytes can not disconnect these 
> existing trojan when my notebook connect internet
> 
> after run a few minutes, the program stopped, but i have 
> already kept create process, why the whole program end?
> 
> why and how to debug when error in for proc in psutil.process_iter()?
> 
> 
> import os
> import psutil
> import multiprocessing
> import time
> import sys
> 
> def cleantask():
> p = os.popen("netstat -ano")
> while 1:
> line = p.readline()
> if "TCP" in line or "UDP" in line:
> linelist = line.split()
> if len(linelist) > 4:
> if "LISTEN" in str(linelist[3]):
> for proc in psutil.process_iter():
> try:
> if "pop" not in str(proc.name).tolower():
> os.system("taskkill /f /pid 
> "+str(proc._pid))
> except:
> dummy = 1
> #print "Unexpected error:", 
> sys.exc_info()[0]
> #print "Unexpected error:", 
> sys.exc_info()[1]
> if "ESTABLISHED" in str(linelist[3]):
> if "127.0.0.1" not in str(linelist[2]):
> for proc in psutil.process_iter():
> try:
> if str(linelist[4]) in 
> str(proc._pid):
> 
> print(str(linelist[2])+","+str(linelist[4])+","+proc.name)
> if "111.221" not in 
> str(linelist[2]) and "explorer.exe" not in str(proc.name).tolower():
> os.system("taskkill /f 
> /pid "+str(proc._pid))
> except:
> dummy = 1
> #print "Unexpected error:", 
> sys.exc_info()[0]
> #print "Unexpected error:", 
> sys.exc_info()[1]
> print(line)
> if not line: break
> 
> if __name__ == '__main__':
> print("main")
> try:
> numberofrunning = 0
> plist = []
> for ii in range(0,5):  
> p = multiprocessing.Process(target=cleantask(), args=(0,))
> p.start()
> plist.append(p)
> numberofrunning = numberofrunning + 1
> time.sleep(1)
> for pp in plist:
> pp.join()
>   if pp.is_alive() == False:
> numberofrunning = numberofrunning - 1
> plist.remove(pp)
> if numberofrunning > 10:
> print "more than 10 process"
> else:
> print("number of process = " + str(numberofrunning))
> if numberofrunning <= 5:
> p = 
> multiprocessing.Process(target=cleantask(), args=(0,))
> p.start()
> plist.append(p)
> numberofrunning = numberofrunning + 1
> time.sleep(1)
> except:
> print "Unexpected error:", sys.exc_info()[0]
> print "Unexpected error:", sys.exc_info()[1]
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


why and how to run forever and debug when error in for proc in psutil.process_iter()?

2017-03-25 Thread Ho Yeung Lee
expect below to run forever and keep running a fixed number of thread in python

would like to kill tasks when process connect internet except chrome
and explorer.exe

i do this because MalwareBytes can not disconnect these existing trojan when my 
notebook connect internet

after run a few minutes, the program stopped, but i have already kept create 
process, why the whole program end?

why and how to debug when error in for proc in psutil.process_iter()?


import os
import psutil
import multiprocessing
import time
import sys

def cleantask():
p = os.popen("netstat -ano")
while 1:
line = p.readline()
if "TCP" in line or "UDP" in line:
linelist = line.split()
if len(linelist) > 4:
if "LISTEN" in str(linelist[3]):
for proc in psutil.process_iter():
try:
if "pop" not in str(proc.name).tolower():
os.system("taskkill /f /pid "+str(proc._pid))
except:
dummy = 1
#print "Unexpected error:", sys.exc_info()[0]
#print "Unexpected error:", sys.exc_info()[1]
if "ESTABLISHED" in str(linelist[3]):
if "127.0.0.1" not in str(linelist[2]):
for proc in psutil.process_iter():
try:
if str(linelist[4]) in str(proc._pid):  
  

print(str(linelist[2])+","+str(linelist[4])+","+proc.name)
if "111.221" not in str(linelist[2]) and 
"explorer.exe" not in str(proc.name).tolower():
os.system("taskkill /f /pid 
"+str(proc._pid))
except:
dummy = 1
#print "Unexpected error:", sys.exc_info()[0]
#print "Unexpected error:", sys.exc_info()[1]
print(line)
if not line: break

if __name__ == '__main__':
print("main")
try:
numberofrunning = 0
plist = []
for ii in range(0,5):  
p = multiprocessing.Process(target=cleantask(), args=(0,))
p.start()
plist.append(p)
numberofrunning = numberofrunning + 1
time.sleep(1)
for pp in plist:
pp.join()
if pp.is_alive() == False:
numberofrunning = numberofrunning - 1
plist.remove(pp)
if numberofrunning > 10:
print "more than 10 process"
else:
print("number of process = " + str(numberofrunning))
if numberofrunning <= 5:
p = multiprocessing.Process(target=cleantask(), args=(0,))
p.start()
plist.append(p)
numberofrunning = numberofrunning + 1
time.sleep(1)
except:
print "Unexpected error:", sys.exc_info()[0]
print "Unexpected error:", sys.exc_info()[1]
-- 
https://mail.python.org/mailman/listinfo/python-list