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


should i kill these two process with python?

2017-03-25 Thread Ho Yeung Lee
  TCP127.0.0.1:1663 127.0.0.1:28091ESTABLISHED 9900
  TCP127.0.0.1:28091127.0.0.1:1663 ESTABLISHED 9532

above two process connect to itself, named ismagent and updateui.exe

are they the malware software?


  TCP127.0.0.1:1663 127.0.0.1:28091ESTABLISHED 9900
  TCP127.0.0.1:7496 0.0.0.0:0  LISTENING   7496
  TCP127.0.0.1:270150.0.0.0:0  LISTENING   9968
  TCP127.0.0.1:280910.0.0.0:0  LISTENING   9532
  TCP127.0.0.1:28091127.0.0.1:1663 ESTABLISHED 9532
  TCP127.0.0.1:432270.0.0.0:0  LISTENING   3772
  TCP127.0.0.1:50.0.0.0:0  LISTENING   9532
  TCP192.168.1.102:1128 210.176.156.35:443 FIN_WAIT_2  5124
  TCP192.168.1.102:1509 64.233.188.102:443 ESTABLISHED 6700
  TCP192.168.1.102:1510 216.58.203.46:443  ESTABLISHED 6700
  TCP192.168.1.102:1511 216.58.203.46:443  ESTABLISHED 6700
  TCP192.168.1.102:1512 216.58.200.5:443   ESTABLISHED 6700
  TCP192.168.1.102:1513 172.217.26.195:443 ESTABLISHED 6700
  TCP192.168.1.102:1514 172.217.26.195:443 CLOSE_WAIT  6700
  TCP192.168.1.102:1898 111.221.29.156:443 ESTABLISHED 1544
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: should i kill these two process with python?

2017-03-25 Thread Chris Angelico
On Sat, Mar 25, 2017 at 7:41 PM, Ho Yeung Lee  wrote:
>   TCP127.0.0.1:1663 127.0.0.1:28091ESTABLISHED 9900
>   TCP127.0.0.1:28091127.0.0.1:1663 ESTABLISHED 9532
>
> above two process connect to itself, named ismagent and updateui.exe
>
> are they the malware software?
>
>
>   TCP127.0.0.1:1663 127.0.0.1:28091ESTABLISHED 9900
>   TCP127.0.0.1:7496 0.0.0.0:0  LISTENING   7496
>   TCP127.0.0.1:270150.0.0.0:0  LISTENING   9968
>   TCP127.0.0.1:280910.0.0.0:0  LISTENING   9532
>   TCP127.0.0.1:28091127.0.0.1:1663 ESTABLISHED 9532
>   TCP127.0.0.1:432270.0.0.0:0  LISTENING   3772
>   TCP127.0.0.1:50.0.0.0:0  LISTENING   9532
>   TCP192.168.1.102:1128 210.176.156.35:443 FIN_WAIT_2  5124
>   TCP192.168.1.102:1509 64.233.188.102:443 ESTABLISHED 6700
>   TCP192.168.1.102:1510 216.58.203.46:443  ESTABLISHED 6700
>   TCP192.168.1.102:1511 216.58.203.46:443  ESTABLISHED 6700
>   TCP192.168.1.102:1512 216.58.200.5:443   ESTABLISHED 6700
>   TCP192.168.1.102:1513 172.217.26.195:443 ESTABLISHED 6700
>   TCP192.168.1.102:1514 172.217.26.195:443 CLOSE_WAIT  6700
>   TCP192.168.1.102:1898 111.221.29.156:443 ESTABLISHED 1544

This question is about systems administration and has nothing to do with Python.

To figure out what each connection represents, you'll have to figure
out what programs are on the two ends. (In the case of listening
sockets, figure out which program is listening.) Then research what's
actually being done by those programs. A simple dump like this is not
going to tell you much about whether it's malware.

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


Re: Python question

2017-03-25 Thread dieter
Abdul Abdul  writes:
> I hope you are doing fine. I have added a question on StackOverflow and
> thought you might have an idea on it. This is the question
> 

I do not want to go into the details of your concrete problem --
just give some general remarks about "pickle".

"pickle" is used for serialization/deserialization of (most) Python objects:
i.e. it can transform a Python object into a string (called a "pickle")
and (later) reconstruct the object from the pickle.

You should not be interested in the internal pickle structure --
keep at the Python level.


For your concrete problem: unpickle your pickle file to get
a Python object; construct a similar Python object with the new data;
pickle that Python object.

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


Re: Python question

2017-03-25 Thread Steve D'Aprano
On Sat, 25 Mar 2017 10:09 am, Cameron Simpson wrote:

> On 24Mar2017 18:08, Abdul Abdul  wrote:
>>I hope you are doing fine. I have added a question on StackOverflow and
>>thought you might have an idea on it. This is the question
>>
> 
> Hi Adbul,
> 
> Please just post the question here, with a nice descriptive Subject: line.
> 
> It is quite possible for people to be reading this list when they do not
> have web access (eg offline on a train, as I sometimes do) and it is
> anyway annoying to have to open a web browser to see what you are asking
> about, and doubly annoying to copy from that question into the list for
> replies.


I solve that problem by hitting Delete on the original post, ESPECIALLY if
they BCC or CC me without a good excuse. As I was in this case: the OP
BCCed me in his post. I'm not *that* special, so my guess is that he did a
mass BCC of many regulars here, which makes this spam.

Judging from the question on Stackoverflow, I think he's just trying to
drive eyeballs to the question so he can get higher reputation. It is a
silly question: he says he has a pickle file containing an image file, and
he's asking (1) what's in the pickle file, and (2) how can he create an
identical pickle file containing a different image.

The answer to (1) is "Whatever you put in it".

Or possibly malware: he links to an actual pickle file he has put up on-line
somewhere. Anyone brave enough to unpickle it in a sandbox and report on
whether it contains what he says it contains? Remember that pickles can
contain arbitrary executable code.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Who are the "spacists"?

2017-03-25 Thread Ian Kelly
On Tue, Mar 21, 2017 at 7:28 PM, Ben Finney  wrote:
> Grant Edwards  writes:
>
>> Question: is it still successfull trolling if we all knew that was the
>> intent and are just playing along for the entertainment value?
>
> Yes, it creates more noise and drives away signal from people who don't
> want to be in a noisy environment. That is success for the troll.

+1. Arguing with trolls is like tic-tac-toe or global thermonuclear
war: the only way to win is not to play.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python question

2017-03-25 Thread Terry Reedy

On 3/25/2017 6:50 AM, Steve D'Aprano wrote:

On Sat, 25 Mar 2017 10:09 am, Cameron Simpson wrote:


On 24Mar2017 18:08, Abdul Abdul  wrote:

I hope you are doing fine. I have added a question on StackOverflow and
thought you might have an idea on it. This is the question



Hi Adbul,

Please just post the question here, with a nice descriptive Subject: line.

It is quite possible for people to be reading this list when they do not
have web access (eg offline on a train, as I sometimes do) and it is
anyway annoying to have to open a web browser to see what you are asking
about, and doubly annoying to copy from that question into the list for
replies.



I solve that problem by hitting Delete on the original post, ESPECIALLY if
they BCC or CC me without a good excuse. As I was in this case: the OP
BCCed me in his post. I'm not *that* special, so my guess is that he did a
mass BCC of many regulars here, which makes this spam.


I got the BCC also and was puzzled why.

--
Terry Jan Reedy

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


Re: Python question

2017-03-25 Thread MRAB

On 2017-03-25 20:10, Terry Reedy wrote:

On 3/25/2017 6:50 AM, Steve D'Aprano wrote:

On Sat, 25 Mar 2017 10:09 am, Cameron Simpson wrote:


On 24Mar2017 18:08, Abdul Abdul  wrote:

I hope you are doing fine. I have added a question on StackOverflow and
thought you might have an idea on it. This is the question



Hi Adbul,

Please just post the question here, with a nice descriptive Subject: line.

It is quite possible for people to be reading this list when they do not
have web access (eg offline on a train, as I sometimes do) and it is
anyway annoying to have to open a web browser to see what you are asking
about, and doubly annoying to copy from that question into the list for
replies.



I solve that problem by hitting Delete on the original post, ESPECIALLY if
they BCC or CC me without a good excuse. As I was in this case: the OP
BCCed me in his post. I'm not *that* special, so my guess is that he did a
mass BCC of many regulars here, which makes this spam.


I got the BCC also and was puzzled why.


Same here.

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


Re: syntax error in first-time user script

2017-03-25 Thread john polo
I had a misconception of how the Python interpreter works. If I have a 
script, call it example.py, in order to run it, I shouldn't be in the 
interpreter? In other words, I should be at the Windows command prompt, 
for example


C:/test> python example.py

and not

>>> python example.py

?

So, if I am already on >>> and have a problem with a script and need to 
edit it and want to run the script again, how do I do that? Do I exit 
the interpreter and start it again? Or is there a different way to run 
the script once the interpreter is active and I am at >>> ?


Cheers,
John
--
https://mail.python.org/mailman/listinfo/python-list


Re: PEOPLE! PLEASE! [ WAS: Re: Who are the "spacists"? ]

2017-03-25 Thread Joel Goldstick
On Sat, Mar 25, 2017 at 3:40 PM, Gilmeh Serda
 wrote:
>
>>> So Python supports both spaces and tabs for indentation.
>
> People!
>
> This is as far from normal conversation about Python as it gets!
>
> Keep this shit to yourselves, PLEASE!
>
> Using an editor worth the name, makes it a non issue (since it can
> convert between one and the other, Eclipse/LiClipse comes to mind). Get
> real, and think before you post/send!
>
> --
> Gilmeh
> --
> https://mail.python.org/mailman/listinfo/python-list

+1


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEOPLE! PLEASE! [ WAS: Re: Who are the "spacists"? ]

2017-03-25 Thread Michael Torrie
On 03/25/2017 01:40 PM, Gilmeh Serda wrote:
> 
>>> So Python supports both spaces and tabs for indentation.
> 
> People!
> 
> This is as far from normal conversation about Python as it gets!
> 
> Keep this shit to yourselves, PLEASE!
> 
> Using an editor worth the name, makes it a non issue (since it can 
> convert between one and the other, Eclipse/LiClipse comes to mind). Get 
> real, and think before you post/send!

I agree, although this thread had pretty much died on its own before you
posted to it. Our troll seems to have slunk off, having done his
trolling.  Peace had returned it seemed.  Unless the mailing list mods
finally banned the guy... either way I haven't seen any posts in a while.

Also USENET has a long tradition of killfiles. And entire threads can be
muted on most clients, including e-mail clients. I recommend you and
everyone else use these tools.

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


Re: Python question

2017-03-25 Thread Erik

On 25/03/17 20:26, MRAB wrote:

On 2017-03-25 20:10, Terry Reedy wrote:

On 3/25/2017 6:50 AM, Steve D'Aprano wrote:

they BCC or CC me without a good excuse. As I was in this case: the OP
BCCed me in his post. I'm not *that* special, so my guess is that he
did a
mass BCC of many regulars here, which makes this spam.


I got the BCC also and was puzzled why.


Same here.


Me too, and I'm hardly a prolific poster compared to some of you lot.

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


Re: PEOPLE! PLEASE! [ WAS: Re: Who are the "spacists"? ]

2017-03-25 Thread Mikhail V
On 26 March 2017 at 00:01, Michael Torrie  wrote:
> On 03/25/2017 01:40 PM, Gilmeh Serda wrote:
>>
 So Python supports both spaces and tabs for indentation.
>>
>> People!
>>
>> This is as far from normal conversation about Python as it gets!
>>
>> Keep this shit to yourselves, PLEASE!
>>
>> Using an editor worth the name, makes it a non issue (since it can
>> convert between one and the other, Eclipse/LiClipse comes to mind). Get
>> real, and think before you post/send!
>
> I agree, although this thread had pretty much died on its own before you
> posted to it. Our troll seems to have slunk off, having done his
> trolling.  Peace had returned it seemed.  Unless the mailing list mods
> finally banned the guy... either way I haven't seen any posts in a while.

Oh don't turn it into drama please, it was interesting discussion.
Sad is that many are more in sociology than technology.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python question

2017-03-25 Thread Abdul Abdul
Hi Cameron,

Thanks for your kind reply and suggestion. Sure, please find my question
below. I also show the different edits made and what errors emerged after
those edits. Thanks for your support!

I have the following code portion for a convolutional neural network:

import numpy as np
import matplotlib.pyplot as plt
import cifar_tools
import tensorflow as tf

data, labels = cifar_tools.read_data('C:\\Users\\abc\\Desktop\\temp')

x = tf.placeholder(tf.float32, [None, 150 * 150])
y = tf.placeholder(tf.float32, [None, 2])

w1 = tf.Variable(tf.random_normal([5, 5, 1, 64]))
b1 = tf.Variable(tf.random_normal([64]))

w2 = tf.Variable(tf.random_normal([5, 5, 64, 64]))
b2 = tf.Variable(tf.random_normal([64]))

w3 = tf.Variable(tf.random_normal([6*6*64, 1024]))
b3 = tf.Variable(tf.random_normal([1024]))

w_out = tf.Variable(tf.random_normal([1024, 2]))
b_out = tf.Variable(tf.random_normal([2]))

def conv_layer(x,w,b):
conv = tf.nn.conv2d(x,w,strides=[1,1,1,1], padding = 'SAME')
conv_with_b = tf.nn.bias_add(conv,b)
conv_out = tf.nn.relu(conv_with_b)
return conv_out

def maxpool_layer(conv,k=2):
return tf.nn.max_pool(conv, ksize=[1,k,k,1], strides=[1,k,k,1],
padding='SAME')

def model():
x_reshaped = tf.reshape(x, shape=[-1,150,150,1])

conv_out1 = conv_layer(x_reshaped, w1, b1)
maxpool_out1 = maxpool_layer(conv_out1)
norm1 = tf.nn.lrn(maxpool_out1, 4, bias=1.0, alpha=0.001/9.0, beta=0.75)

conv_out2 = conv_layer(norm1, w2, b2)
maxpool_out2 = maxpool_layer(conv_out2)
norm2 = tf.nn.lrn(maxpool_out2, 4, bias=1.0, alpha=0.001/9.0, beta=0.75)

maxpool_reshaped = tf.reshape(maxpool_out2,
[-1,w3.get_shape().as_list()[0]])
local = tf.add(tf.matmul(maxpool_reshaped, w3), b3)
local_out = tf.nn.relu(local)

out = tf.add(tf.matmul(local_out, w_out), b_out)
return out

model_op = model()

cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(model_op,
y))
train_op = tf.train.AdamOptimizer(learning_rate=0.001).minimize(cost)

correct_pred = tf.equal(tf.argmax(model_op, 1), tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(correct_pred,tf.float32))

I'm reading `150x150` grayscale images, but couldn't understand the
following error I'm having:

EPOCH 0
Traceback (most recent call last):
  File
"C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line
1021, in _do_call
return fn(*args)
  File
"C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line
1003, in _run_fn
status, run_metadata)
  File "C:\Python35\lib\contextlib.py", line 66, in __exit__
next(self.gen)
  File
"C:\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py",
line 469, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to
reshape is a tensor with 92416 values, but the requested shape requires a
multiple of 2304
 [[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32,
_device="/job:localhost/replica:0/task:0/cpu:0"](MaxPool_1,
Reshape_1/shape)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "cnn.py", line 70, in 
_, accuracy_val = sess.run([train_op, accuracy], feed_dict={x:
batch_data, y: batch_onehot_vals})
  File
"C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line
766, in run
run_metadata_ptr)
  File
"C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line
964, in _run
feed_dict_string, options, run_metadata)
  File
"C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line
1014, in _do_run
target_list, options, run_metadata)
  File
"C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line
1034, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to
reshape is a tensor with 92416 values, but the requested shape requires a
multiple of 2304
 [[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32,
_device="/job:localhost/replica:0/task:0/cpu:0"](MaxPool_1,
Reshape_1/shape)]]

Caused by op 'Reshape_1', defined at:
  File "cnn.py", line 50, in 
model_op = model()
  File "cnn.py", line 43, in model
maxpool_reshaped = tf.reshape(maxpool_out2,
[-1,w3.get_shape().as_list()[0]])
  File
"C:\Python35\lib\site-packages\tensorflow\python\ops\gen_array_ops.py",
line 2448, in reshape
name=name)
  File
"C:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py",
line 759, in apply_op
op_def=op_def)
  File
"C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line
2240, in create_op
original_op=self._default_original_op, op_def=o

RE: syntax error in first-time user script

2017-03-25 Thread Deborah Swanson
john polo wrote, on March 25, 2017 2:45 PM
> 
> I had a misconception of how the Python interpreter works. If 
> I have a 
> script, call it example.py, in order to run it, I shouldn't be in the 
> interpreter? In other words, I should be at the Windows 
> command prompt, 
> for example
> 
> C:/test> python example.py
> 
> and not
> 
>  >>> python example.py
> 
> ?
> 
> So, if I am already on >>> and have a problem with a script 
> and need to 
> edit it and want to run the script again, how do I do that? Do I exit 
> the interpreter and start it again? Or is there a different 
> way to run 
> the script once the interpreter is active and I am at >>> ?
> 
> Cheers,
> John

In IDLE, to run a script, open the .py file from the file menu and click
Run Module from the Run menu. You can easily edit the .py file while
it's open in the editor

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


RE: should i kill these two process with python?

2017-03-25 Thread Deborah Swanson
Chris Angelico wrote, on Saturday, March 25, 2017 1:53 AM
> 
> On Sat, Mar 25, 2017 at 7:41 PM, Ho Yeung Lee 
>  wrote:
> >   TCP127.0.0.1:1663 127.0.0.1:28091
> ESTABLISHED 9900
> >   TCP127.0.0.1:28091127.0.0.1:1663 
> ESTABLISHED 9532
> >
> > above two process connect to itself, named ismagent and updateui.exe
> >
> > are they the malware software?
> >
> >
> >   TCP127.0.0.1:1663 127.0.0.1:28091
> ESTABLISHED 9900
> >   TCP127.0.0.1:7496 0.0.0.0:0  
> LISTENING   7496
> >   TCP127.0.0.1:270150.0.0.0:0  
> LISTENING   9968
> >   TCP127.0.0.1:280910.0.0.0:0  
> LISTENING   9532
> >   TCP127.0.0.1:28091127.0.0.1:1663 
> ESTABLISHED 9532
> >   TCP127.0.0.1:432270.0.0.0:0  
> LISTENING   3772
> >   TCP127.0.0.1:50.0.0.0:0  
> LISTENING   9532
> >   TCP192.168.1.102:1128 210.176.156.35:443 
> FIN_WAIT_2  5124
> >   TCP192.168.1.102:1509 64.233.188.102:443 
> ESTABLISHED 6700
> >   TCP192.168.1.102:1510 216.58.203.46:443  
> ESTABLISHED 6700
> >   TCP192.168.1.102:1511 216.58.203.46:443  
> ESTABLISHED 6700
> >   TCP192.168.1.102:1512 216.58.200.5:443   
> ESTABLISHED 6700
> >   TCP192.168.1.102:1513 172.217.26.195:443 
> ESTABLISHED 6700
> >   TCP192.168.1.102:1514 172.217.26.195:443 
> CLOSE_WAIT  6700
> >   TCP192.168.1.102:1898 111.221.29.156:443 
> ESTABLISHED 1544
> 
> This question is about systems administration and has nothing 
> to do with Python.
> 
> To figure out what each connection represents, you'll have to 
> figure out what programs are on the two ends. (In the case of 
> listening sockets, figure out which program is listening.) 
> Then research what's actually being done by those programs. A 
> simple dump like this is not going to tell you much about 
> whether it's malware.
> 
> ChrisA

You can also look up the IP addresses with a DNS lookup tool that aren't
your machine (127.0.0.1 and 192.168.1.102). This may be helpful if you
recognize who they are, or you can google the IP addresses and/or their
owners. If they're malware, Google will have lots of pages on them.

This looks like a readout from Essential Net Tools running in Express
mode. If you select Addvanced mode, ENT will tell you the process name
and lots of other good stuff for each entry, plus ENT is a full network
toolbox and you won't need Google.

Deborah

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


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


Re: Python question

2017-03-25 Thread cs

On 26Mar2017 00:11, Erik  wrote:

On 25/03/17 20:26, MRAB wrote:

On 2017-03-25 20:10, Terry Reedy wrote:

On 3/25/2017 6:50 AM, Steve D'Aprano wrote:

they BCC or CC me without a good excuse. As I was in this case: the OP
BCCed me in his post. I'm not *that* special, so my guess is that he
did a
mass BCC of many regulars here, which makes this spam.

I got the BCC also and was puzzled why.

Same here.

Me too, and I'm hardly a prolific poster compared to some of you lot.


Guys guys guys,

1: He BCCed the list, not us individually. Look at the headers.

2: I got a perfectly civil and informative response from him.

So treat him as up front!

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Who are the "spacists"?

2017-03-25 Thread Wildman via Python-list
On Tue, 21 Mar 2017 15:15:14 +0100, Mikhail V wrote:

> And on linux console, by default one does not even have good
> possibilities for text-mode pseudographics, it was more relevant
> in DOS where one had rich possibilities and programmable
> binary fonts.
> 
> Mikhail

Nonsense.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


C-Python and Endianness

2017-03-25 Thread Ganesh Pal
Hello Team ,




I want  to write the  hexadecimal string that is passed from python  as  it
is  on disk in C  , my problem is that  the values are getting stored  in
little endian and


the values are  swapped it has been quite a pain for me to fix this , any
suggestion on how to fix this (I am on Python 2.7 and Linux).




Example  :


 if I pass a PyObject  i.e “abcdef12345123”  it should be written on disk
 at the given offset as it  i.e. “abcdef12345123”





CLI:



#inject_failures.py --optype=add --fixcrc=1 --object=baddr
 --baddr=2,3,773463552:512  --offset=16 --mirror=1
 --op_value='abcdef12345123' --size=8



(op_value is the new variable that is passed as string )



static PyObject *

py_corrupt_disk_object(PyObject *self, PyObject *args)

{



int size, optype, fixcrc;

long offset;

PyObject *baddr;

char *op_value = NULL;



if (!PyArg_ParseTuple(args,"Oliisi", &baddr, &offset, &size,
&optype,

&op_value,&fixcrc))

Py_RETURN_NONE;



d_locn_t locn = {};

locn.idx.devid  = ((struct py_ifs_baddr*)baddr)->baddr.devid;

locn.idx.drive  = ((struct py_ifs_baddr*)baddr)->baddr.drive;

locn.idx.subidx = ((struct py_ifs_baddr*)baddr)->baddr._subblk;

locn.idx.index  = ((struct py_ifs_baddr*)baddr)->baddr._block;



d_print("Printing args in py_corrupt_disk_object: \n");

d_print("offset %lu \n",offset);

d_print("fixcrc %d \n",fixcrc);

d_print("size %d \n",size);

d_print("optype %d \n",optype);

d_print("op_value %s \n",op_value);





d_cpr_write(&locn, offset, size, optype, op_value, fixcrc);

Py_RETURN_NONE;

}





PyObject*

d_cpr_write(d_locn_t *locn, int offset, int size, int optype, char
*op_value, int fixcrc)

{



cpr_obj* obj = NULL;

struct po_typeinfo *tinfo = NULL;

int obj_size = 0;

d_print("The Values inside d_cpr_write():\n");

d_print("offset %d \n",offset);

d_print("fixcrc %d \n",fixcrc);

d_print("size %d \n",size);

d_print("optype %d \n",optype);

d_print("op_value %s \n",op_value);





if (locn->idx.subidx & BADDR_SIZE_512) {

obj_size = BUFFER_512;

tinfo = find_object('i');

if (locn_iaddr_to_linsnap(locn) != d_OK) {

d_log(d_ERR, "lin snap conversion failed\n");

Py_RETURN_NONE;

}

locn->flags |= DLFLAG_HASXIADDRHINT;

locn->xiaddrhint = d_index_to_baddr(locn->idx);

} else {

obj_size = BUFFER_8192;

tinfo = find_object('b');

}



if (tinfo == NULL) {

d_log(d_ERR, "Only Object i or b supported\n");

Py_RETURN_NONE;

}



obj = alloc_objarg();



// create cpr object

obj->tinfo = tinfo;

obj->locn = *locn;



unsigned char *buff = NULL;

if (!(buff = alloca(obj_size))) {

d_log(d_ERR, "buffer allocation failed\n");

Py_RETURN_NONE;

}



int index, xfered, bit_offset;



if ((xfered = (*obj->tinfo->read)(&obj->locn, buff, obj_size)) < 0)
{

d_log(d_ERR, "read failed %d\n", xfered);

Py_RETURN_NONE;

}



if (obj->tinfo->insane != NULL) {

if ((*obj->tinfo->insane)(&obj->locn, buff, obj_size, 0) <
0) {

d_log(d_ERR, "%c object sanity check failed\n",

obj->tinfo->type);

Py_RETURN_NONE;

}

}



   d_print("Entering optype\n");

if (optype == 2) { //overwrite

unsigned long opval = strtol(op_value, NULL, 16);

d_print("after rev =%ld ", opval);

memcpy(&buff[offset], &opval, sizeof(opval));



 }//End of overwrite

if (fixcrc)

obj->locn.flags |= DLFLAG_WRITE_CRC;



if (!obj->tinfo->write) {

d_log(d_ERR, "no write function supported\n");

Py_RETURN_NONE;

}



if ((xfered = (*obj->tinfo->write)(&obj->locn, buff, obj_size)) <
0) {

d_log(d_ERR, "write failed %d\n", xfered);

Py_RETURN_NONE;

}



Py_RETURN_NONE;

}





Output:



pipe1-2# inject_failures.py --optype=add --fixcrc=1 --object=baddr
 --baddr=2,3,773463552:512  --offset=16 --mirror=1
 --op_value='abcdef12345123' --size=8

> /usr/local_qa/bin/isi_corrupt.py(848)main()

-> if 'add' in options.optype and options.op_value is None:

(Pdb) c

c

> /usr/local_qa/bin/ inject_failures.py (185)corrupt_diskobject()

-> logging.info("Corrupting disk object %s at %s", obj_type, disk_object)

(Pdb) c

Printing args in py_corrupt_disk_object:

offset 16

fixcrc 1

size 8

optype