how to replace maltipal char from string and substitute new char
Hi Team, How to replace multipal char from string and substitute with new char with one line code Ex: str = "9.0(3)X7(2) " ===> 9.0.3.X7.2 need to replace occurrence of '(',')' with dot(.) chars output: 9.0.3.X7.2 Thanks, -- https://mail.python.org/mailman/listinfo/python-list
sendline buffer
Hi Team, I have faced fallowing issue:: dev.sendline("*show version*") <<< its printing "show version output" dev.sendline("*show module*") <<< its printing "shoe module output" *Runing again* dev.sendline("show veriosn") <<< its runing 2nd time again dev.before *output is not consistence means some time it printing "shoe version output" or some time its printing only "show module output"* can you please let me know , how to resolve the issue. Thanks, Iranna M -- https://mail.python.org/mailman/listinfo/python-list
Pexpect
Hi Team, The fallowing script(function) is working if its in PDB mode(trace line by line) but same script is not working if its remove/comment PDB and run one shot. log.info("Time out expection") uut_con1 = pexpect.spawn('telnet %s'%power_ip) uut_con1.logfile = sys.stdout uut_con1.delaybeforesend = None time.sleep(30) uut_con1.send("%s\r" % username) uut_con1.expect([r"Password:"],timeout=30) uut_con1.send("%s\r" % pass_word) time.sleep(30) uut_con1.send("\r") uut_con1.expect([r'#?'],timeout=30) uut_con1.send("power outlets %d off\r"%outlet) uut_con1.expect([r'wish to turn outlet'],timeout=30) uut_con1.send("y\r") uut_con1.send("\r") uut_con1.expect([r'#?'],timeout=30) uut_con1.send("power outlets %d on\r"%outlet) uut_con1.expect([r'wish to turn outlet'],timeout=30) uut_con1.send("y\r") uut_con1.send("\r") uut_con1.expect([r'#?'],timeout=30) uut_con1.close() uut_con.close() time.sleep(300) check_prompt(self,username,pass_word,dev_ip,dev_port,power_ip,outlet) *I got fallowing error:* 2016-12-10T02:24:42: %aetest-INFO: Time out expection Trying 172.31.206.143... Connected to 172.31.206.143. Escape character is '^]'. Login for PX2 CLI Username: admin power outlets 21 off Welcome to PX2 CLI! Last login: 2001-06-30 11:53:59 EDT [CLI (Telnet) from 172.31.144.6] # # power outlets 21 off yower outlets 21 on outlet 21 off? [y/n] y power outlets 21 on # 2016-12-10T02:26:12: %aetest-ERROR: Caught exception during execution: 2016-12-10T02:26:13: %aetest-ERROR: Traceback (most recent call last): 2016-12-10T02:26:13: %aetest-ERROR: File "/auto/n3k-qa/CODC/rajtamil/pyATS2.7/hlite/eor/systest/scripts/NAT/ATS_CLEAN_N9K.py", line 354, in connect_devices 2016-12-10T02:26:13: %aetest-ERROR: check_prompt(self,username,pass_word,dev_ip,dev_port,power_ip,outlet) 2016-12-10T02:26:13: %aetest-ERROR: File "/auto/n3k-qa/CODC/rajtamil/pyATS2.7/hlite/eor/systest/scripts/NAT/ATS_CLEAN_N9K.py", line 282, in check_prompt 2016-12-10T02:26:13: %aetest-ERROR: uut_con1.expect([r'wish to turn outlet'],timeout=30) 2016-12-10T02:26:13: %aetest-ERROR: File "/auto/n3k-qa/CODC/svanalin/pyats2/lib/python2.7/site-packages/pexpect/spawnbase.py", line 321, in expect 2016-12-10T02:26:13: %aetest-ERROR: timeout, searchwindowsize, async) 2016-12-10T02:26:13: %aetest-ERROR: File "/auto/n3k-qa/CODC/svanalin/pyats2/lib/python2.7/site-packages/pexpect/spawnbase.py", line 345, in expect_list 2016-12-10T02:26:13: %aetest-ERROR: return exp.expect_loop(timeout) 2016-12-10T02:26:13: %aetest-ERROR: File "/auto/n3k-qa/CODC/svanalin/pyats2/lib/python2.7/site-packages/pexpect/expect.py", line 107, in expect_loop 2016-12-10T02:26:13: %aetest-ERROR: return self.timeout(e) 2016-12-10T02:26:13: %aetest-ERROR: File "/auto/n3k-qa/CODC/svanalin/pyats2/lib/python2.7/site-packages/pexpect/expect.py", line 70, in timeout 2016-12-10T02:26:13: %aetest-ERROR: raise TIMEOUT(msg) 2016-12-10T02:26:13: %aetest-ERROR: TIMEOUT: Timeout exceeded. 2016-12-10T02:26:13: %aetest-ERROR: 2016-12-10T02:26:13: %aetest-ERROR: command: /usr/bin/telnet 2016-12-10T02:26:13: %aetest-ERROR: args: ['/usr/bin/telnet', '172.31.206.143'] 2016-12-10T02:26:13: %aetest-ERROR: buffer (last 100 chars): ' 21 off? [y/n] y\r\n\r\npower outlets 21 on\r\n# ' 2016-12-10T02:26:13: %aetest-ERROR: before (last 100 chars): ' 21 off? [y/n] y\r\n\r\npower outlets 21 on\r\n# ' 2016-12-10T02:26:13: %aetest-ERROR: after: 2016-12-10T02:26:13: %aetest-ERROR: match: None 2016-12-10T02:26:13: %aetest-ERROR: match_index: None 2016-12-10T02:26:13: %aetest-ERROR: exitstatus: None 2016-12-10T02:26:13: %aetest-ERROR: flag_eof: False 2016-12-10T02:26:13: %aetest-ERROR: pid: 9163 2016-12-10T02:26:13: %aetest-ERROR: child_fd: 18 2016-12-10T02:26:13: %aetest-ERROR: closed: False 2016-12-10T02:26:13: %aetest-ERROR: timeout: 30 2016-12-10T02:26:13: %aetest-ERROR: delimiter: 2016-12-10T02:26:13: %aetest-ERROR: logfile: ', mode 'w' at 0xf7712078> 2016-12-10T02:26:13: %aetest-ERROR: logfile_read: None 2016-12-10T02:26:13: %aetest-ERROR: logfile_send: None 2016-12-10T02:26:13: %aetest-ERROR: maxread: 2000 2016-12-10T02:26:13: %aetest-ERROR: ignorecase: False 2016-12-10T02:26:13: %aetest-ERROR: searchwindowsize: None 2016-12-10T02:26:13: %aetest-ERROR: delaybeforesend: None 2016-12-10T02:26:13: %aetest-ERROR: delayafterclose: 0.1 2016-12-10T02:26:13: %aetest-ERROR: delayafterterminate: 0.1 2016-12-10T02:26:13: %aetest-ERROR: searcher: searcher_re: 2016-12-10T02:26:13: %aetest-ERROR: 0: re.compile("wish to turn outlet") 2016-12-10T02:26:13: %aetest-INFO: The result of subsection connect_devices is => ERRORED Regards, Iranna M -- htt
Pexpect
Hi Team, How to match latter(caps and small) ,numbers and # symbol in python pexpect. Thanks, Iranna M -- https://mail.python.org/mailman/listinfo/python-list
Pexpect
Hi Team, How to match latter(caps and small) ,numbers and # symbol in python pexpect. Thanks, Iranna M -- https://mail.python.org/mailman/listinfo/python-list
Find and append file path
Hi Team, How to append file path and find the latest folder according to the latest date: CLI input :"/root/user/branches/xyz" i want to find latest file within CLI input path and append to given CLI path Example: CLI Input: /root/user/branches/xyz find latest file and append to CLI path: "/root/user/branches/xyz/Apple" -- https://mail.python.org/mailman/listinfo/python-list
Regex Doubts
Hi Team, how to achieve fallowing expected output? str_output= """ MOD1 memory : 2 valid1790 free MOD2 memory : 128 valid 128 free UDP Aware *MEMR*: 0 valid 0 free *MEMR : 21 valid 491 free https://mail.python.org/mailman/listinfo/python-list
Re: Regex Doubts
Hi Cameron. str_output= """ MOD1 memory: 2 valid1790 free MOD2 memory: 128 valid 128 free UDP Aware MEMR : 0 valid0 free *MEMR* : 21 valid 491 free Feature XYZ: 3 valid13 free Feature PQR : 0 valid16 free Feature MNO : 0 valid2 free """ pattern = re.findall(r'MEMR\s+\:\s+([0-9]+)\s+valid \s+([0-9]+)\s+free ', str_output) it produce fallowing output:: [('0', '0'), ('21', '491')] [('21' ,'491')] <<<<< how to achieve this output using *"findall with single line code"*? NOTE "MEMR" values are 0 or more then 0 valid/free values Thanks, Iranna On Fri, Mar 30, 2018 at 12:43 PM, Cameron Simpson wrote: > On 30Mar2018 11:46, Iranna Mathapati wrote: > >> how to achieve fallowing expected output? >> >> str_output= """ >> >> MOD1 memory : 2 valid1790 free >> MOD2 memory : 128 valid 128 free >> UDP Aware *MEMR*: 0 valid 0 free *MEMR >> : 21 valid 491 free >> <<<<> Feature XYZ : 3 valid13 free >> Feature PQR : 0 valid 16 free >> Feature MNO: 0 valid 2 free >> >> """ >> >> i am going to grep MEM values alone and i have tried fallowing Regex: >> >> re.findall(r'MEMR\s+\:\s+([0-9]+)\s+valid \s+([0-9]+)\s+free ', >> str_output) >> >> it produce fallowing output:: >> [('0', '0'), ('21', '491')] >> >> Expected output and i am expecting fallowing output:: >> *[('21' ,'491')] <<<<< how to achieve this output?* >> > > I get an empty list with your str_output text. Is it intact above? Or > modified by the mail program? > > That said, I see that your regexp ends with "free ". Are you sure there is > a space after the word "free" in your input data? There doesn't seems to be > one in your email. Because your regexp requires a final space, if there > isn't one in the input then it will not match. > > It may be that your original data has this final space, hence your matches. > > In which case, there are two "MEMR" words in your input data. Are there > really asterisks ("*") in the input data? Or are they for emphasis? I ask > because you've got some lines ending in "::" in your email, which is > suggestive of some formatting. > > So, supposing that the asterisks are not there, you have two "MEMR : N > valid M free" strings up there. It sounds like you want only the nonzero > one. Notice that your regexp includes: > > [0-9]+ > > to match 1 or more digits. If you don't want to recognise zero values, > consider that any such number doesn't commence with a "0" digit. How would > you modify the regexp above to be more picky? > > Cheers, > Cameron Simpson > -- https://mail.python.org/mailman/listinfo/python-list
Re: Regex Doubts
Thanks a lot Antoon. On Fri, Mar 30, 2018 at 2:51 PM, Antoon Pardon wrote: > On 30-03-18 08:16, Iranna Mathapati wrote: > > Hi Team, > > > > > > how to achieve fallowing expected output? > > > > str_output= """ > > > > MOD1 memory : 2 valid1790 free > > MOD2 memory : 128 valid 128 free > > UDP Aware *MEMR*: 0 valid 0 free *MEMR > >: 21 valid 491 free > > <<<< > Feature XYZ : 3 valid13 free > > Feature PQR : 0 valid 16 free > > Feature MNO: 0 valid 2 free > > > > """ > > > > i am going to grep MEM values alone and i have tried fallowing Regex: > > > > re.findall(r'MEMR\s+\:\s+([0-9]+)\s+valid \s+([0-9]+)\s+free ', > str_output) > > > > it produce fallowing output:: > > [('0', '0'), ('21', '491')] > > > > Expected output and i am expecting fallowing output:: > > *[('21' ,'491')] <<<<< how to achieve this output?* > > I find it hard to find a good answer to your question because you give no > reason why you want to reject the ('0', '0') result. > > Are you uninterested in 0 results? > Are you only interested in lines that start with MEMR and so are not > interested > in lines where the MEMR comes later? > > In the first case you can write: > print(re.findall(r'MEMR\s+\:\s+([1-9][0-9]*)\s+valid > \s+([1-9][0-9]*)\s+free', str_output)) > > In the second case you can write: > regex = re.compile(r'^MEMR\s+\:\s+([0-9]+)\s+valid \s+([0-9]+)\s+free', > re.MULTILINE) > print(regex.findall(str_output)) > > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
failed to execute scapy commands from remote server
Hi Team, I have to ssh a remote server and execute scapy commands there. but its able to execute all linux commands from remote server handle I use pexpect and hitting issue. 1. SSH to remote shell via pexpect from current server parser_ip_add='192.168.1.83' child_remote = pexpect.spawn('/usr/bin/ssh',['AST@ {0}'.format(parser_ip_add)]) ssh_newkey = 'Are you sure you want to continue connecting' i=child_remote.expect([pexpect.TIMEOUT, ssh_newkey, 'password:']) if i==2: child_remote.sendline('X') <<< password child_remote.sendline('sudo su') child_remote.expect('password for AST: ') child_remote.sendline('X') >> child_remote.sendline=sendp(arp3,iface='enp6s0f0',count=100) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/site-packages/scapy/sendrecv.py", line 256, in sendp __gen_send(conf.L2socket(iface=iface, *args, **kargs), x, inter=inter, loop=loop, count=count, verbose=verbose, realtime=realtime) File "/usr/local/lib/python2.7/site-packages/scapy/arch/linux.py", line 425, in __init__ self.ins.bind((iface, type)) File "/usr/local/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 19] No such device >>> child_remote.sendline(sendp(arp3,iface='enp6s0f0',count=100)) KeyboardInterrupt -- https://mail.python.org/mailman/listinfo/python-list
how to replace line on particular line in file[no need to write it back whole file again]
Hi Team, How to replace particular line text with new text on a file i have below code but its writing whole code. def replace_line(file_name, line_num, text): lines = open(file_name, 'r').readlines() lines[line_num] = text out = open(file_name, 'w') out.writelines(lines) < *writing back whole file instead of particular line* out.close() replace_line('stats.txt', 0, 'good') Thanks, Iranna M -- https://mail.python.org/mailman/listinfo/python-list
Re: how to replace line on particular line in file[no need to write it back whole file again]
Thanks Dennis Lee and Thomas On Thu, Oct 11, 2018 at 6:32 PM Dennis Lee Bieber wrote: > On Thu, 11 Oct 2018 15:14:49 +0530, Iranna Mathapati > declaimed the following: > > >Hi Team, > > > >How to replace particular line text with new text on a file > >i have below code but its writing whole code. > > > > > For C-style streams (which seem to have taken over every operating > system) in which "lines" are determined by specific characters in the > stream, you can only "replace" a line IF THE REPLACEMENT IS THE EXACT SAME > SIZE! If there is any difference in length of the input and output lines, > you have to read/write everything from the line to the end of the file. > > I emphasize "C-style streams" as there were operating systems that > did > support other file organizations natively. Xerox CP-V offered > "consecutive", "keyed", and "random" file organizations. > > "Consecutive" being the closest to streams -- pure sequentially > written > data. > > "Keyed" files used a multi-level ISAM structure -- which is what > was > used by the text editor and by the FORTRAN direct-access mode (line/record > numbers were used as the ISAM key). In these, replacing a line meant > writing a new line and updating the ISAM headers to point to > the new line. Periodically one would have to pack the file to reclaim > unused/freed space. > > "Random" files were an organization in which the OS did /nothing/. > These files were created as a predetermined maximum size, and were > allocated as a contiguous section of disk space -- the OS didn't even > bother tracking blocks. An application basically was given two pieces of > information: the starting address on disk, and the total length of the > allocation. ALL data management had to be done by the application. > > Past that, there is the concept of a fixed-length record. ALL > records > (lines) in the file having the same predefined maximum length. Internally, > each record would either have a length datum at the beginning, or use some > special character to indicate where the end of the record's data really is > -- but all I/O was performed on the full . Even > TRSDOS/LS-DOS (TRS-80 Model III/4) supported fixed-length I/O in the OS, > though the maximum record length was one disk sector (256 bytes; shorter > records definitions were permitted and the system /did/ pack them into disk > space rather than wasting the tail of the sector). Fixed length schemes > typically permit direct access > > x = read(rec=123) > > write(y, rec=123) > > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
How to login remote windos device using python
Hi Team, can you please let me know, How to login the remote Windows machine using python?? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: How to login remote windos device using python
Hi Kyle, I have tried with as per above attached links and it leads following error: NOTE: Its able to connect local Failed to connect remote windows >>> import wmi >>> c = wmi.WMI("XX.XX.XX.XX", user=r"XXX\XXX", password="") Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\wmi.py", line 1290, in connect handle_com_error () File "C:\Python27\lib\site-packages\wmi.py", line 241, in handle_com_error raise klass (com_error=err) wmi.x_wmi: On Tue, Aug 20, 2019 at 7:03 AM Kyle Stanley wrote: > I would recommend checking out WMI: https://pypi.org/project/WMI/ > > For remote connection as a named user (official WMI docs): > http://timgolden.me.uk/python/wmi/tutorial.html#connecting-to-a-remote-machine-as-a-named-user > > Also, another example (unofficial): > https://stackoverflow.com/questions/18961213/how-to-connect-to-a-remote-windows-machine-to-execute-commands-using-python. > This was done in Python2, but the example is still useful. > > On Mon, Aug 19, 2019 at 2:11 PM Iranna Mathapati > wrote: > >> Hi Team, >> >> can you please let me know, How to login the remote Windows machine using >> python?? >> >> Thanks >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- https://mail.python.org/mailman/listinfo/python-list
Is it able to connect remote win system from Linux using python
Hi Team, can you please let me know , is there any module to connect the remote Windows system from Linux using python module? Thanks, Iranna M -- https://mail.python.org/mailman/listinfo/python-list
Re: How to login remote windos device using python
Thanks Kyle Its working fine On Tue, Aug 20, 2019 at 2:45 PM Iranna Mathapati wrote: > Hi Kyle, > > I have tried with as per above attached links and it leads following error: > NOTE: Its able to connect local > > Failed to connect remote windows > >>> import wmi > >>> c = wmi.WMI("XX.XX.XX.XX", user=r"XXX\XXX", password="") > Traceback (most recent call last): > File "", line 1, in > File "C:\Python27\lib\site-packages\wmi.py", line 1290, in connect > handle_com_error () > File "C:\Python27\lib\site-packages\wmi.py", line 241, in > handle_com_error > raise klass (com_error=err) > wmi.x_wmi: occurred.', (0, u'SWbemLocator', u'The RPC server is unavailable. ', None, > 0, -2147023174), None)> > > On Tue, Aug 20, 2019 at 7:03 AM Kyle Stanley wrote: > >> I would recommend checking out WMI: https://pypi.org/project/WMI/ >> >> For remote connection as a named user (official WMI docs): >> http://timgolden.me.uk/python/wmi/tutorial.html#connecting-to-a-remote-machine-as-a-named-user >> >> Also, another example (unofficial): >> https://stackoverflow.com/questions/18961213/how-to-connect-to-a-remote-windows-machine-to-execute-commands-using-python. >> This was done in Python2, but the example is still useful. >> >> On Mon, Aug 19, 2019 at 2:11 PM Iranna Mathapati >> wrote: >> >>> Hi Team, >>> >>> can you please let me know, How to login the remote Windows machine using >>> python?? >>> >>> Thanks >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it able to connect remote win system from Linux using python
Hi Chris, Want to run a command line on the remote windows machine [on powershell command line] from linux device I want to check what are the drivers are installed on the remote window machine from a Linux machine using python. Thanks, On Tue, Aug 20, 2019 at 5:05 PM Chris Green wrote: > Iranna Mathapati wrote: > > Hi Team, > > > > can you please let me know , is there any module to connect the remote > > Windows system from Linux using python module? > > > We need more information, what sort of 'connect' to a remote Windows > system do you want? I.e.:- > > Do you want to run a Windows desktop remotely? > > Do you want to send messages to the Windows machine? > > Do you want to exchange files with the Windows machine? > > Do you want to run a command line on the Windows machine? > > ... or something else? > > -- > Chris Green > ยท > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
how to remove duplicates dict from the list of dictionary based on one of the elements is duplicate in list of dict
Hi, How to remove duplicates dict from the list of dictionary based on one of the duplicate elements in the dictionary, l = [{"component":"software", "version":"1.2" }, {"component":"hardware", "version":"2.2",}, {"component":"driver", "version":"3.2",}, {"component":"firmware", "version":"4.2",}, {"component":"software", "version":"1.9",}, {"component":"hardware", "version":"2.7",} ] need to remove the dict if having same components [in the above example components "software" and "hardware" is duplicated twice expected output: [{"component":"software", "version":"1.2" }, {"component":"hardware", "version":"2.2",}, {"component":"driver", "version":"3.2",}, {"component":"firmware", "version":"4.2",} ] -- https://mail.python.org/mailman/listinfo/python-list
Thread within for loop
Hi team, I tried to run fallowing run, *jobs = []* *sniffer1 = threading.Thread(target=validate_traffic_stats_dy,args= (FT_item_dy,RT_item_dy,forward_path_list_dy,return_path_list_dy,nat_type_list_dy,pkt_dy_1,))* *jobs.append(sniffer1)* *sniffer2 = threading.Thread(target=validate_traffic_stats_st,args=(FT_item_st,RT_item_st,forward_path_list_st,return_path_list_st,nat_type_list_st,pkt_st,))* *jobs.append(sniffer2)* * for local_ip, global_ip in zip(src_ipv4_local_list_st_in_new, src_ipv4_global_list_st_in_new):* *sniffer3 = threading.Thread(target=create_static_nat_entries,args = (uut2_hdl2, direction_in, local_ip,global_ip,))* *jobs.append(sniffer3) * *# Start the threads* *for j in jobs:* *j.start()* *time.sleep(2)* *# Ensure all of the threads have finished* *for j in jobs:* * j.join()* while runing i got below error and hitting in sniffer3 thread Exception in thread Thread-5: Traceback (most recent call last): File "/auto/pysw/cel55/python/2.7.8/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "/auto/pysw/cel55/python/2.7.8/lib/python2.7/threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "/auto/n3k-qa/regression/pyATS2/hlite/eor/systest/scripts/NAT/feature_nat_lib.py", line 50, in create_static_nat_entries {2} add-route'.format(protocol, inside_local_ip, inside_global_ip)) File "../../lib/icon.py", line 899, in iconfig self.hdl.expect('# $') File "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-packages/pexpect/__init__.py", line 1451, in expect timeout, searchwindowsize) File "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-packages/pexpect/__init__.py", line 1466, in expect_list timeout, searchwindowsize) File "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site-packages/pexpect/__init__.py", line 1568, in expect_loop raise TIMEOUT(str(err) + '\n' + str(self)) TIMEOUT: Timeout exceeded. version: 3.3 command: /usr/bin/telnet args: ['/usr/bin/telnet', '172.31.205.170', '2025'] searcher: buffer (last 100 chars): '\rSeoul(config)# config terminal\r\r\n\r\r\nend\r\r\n' before (last 100 chars): '\rSeoul(config)# config terminal\r\r\n\r\r\nend\r\r\n' after: match: None match_index: None exitstatus: None flag_eof: False pid: 17297 child_fd: 8 closed: False timeout: 500 delimiter: logfile: logfile_read: None logfile_send: None maxread: 2000 ignorecase: False searchwindowsize: None delaybeforesend: 0.05 delayafterclose: 0.1 delayafterterminate: 0.1 Can you please let me know what is the issue. Thanks, Iranna M -- https://mail.python.org/mailman/listinfo/python-list
Re: Thread within for loop
Hi , How to fix it and now i got below error for same script *runtimeerror threads can only be started once then* *Thanks,* On Sat, Apr 1, 2017 at 1:15 PM, dieter wrote: > Iranna Mathapati writes: > > ... > > Exception in thread Thread-5: > > Traceback (most recent call last): > > ... > > File > > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site- > packages/pexpect/__init__.py", > > line 1466, in expect_list > > timeout, searchwindowsize) > > File > > "/auto/n3k-qa/CODC/ianandan/pyATS2.7/lib/python2.7/site- > packages/pexpect/__init__.py", > > line 1568, in expect_loop > > raise TIMEOUT(str(err) + '\n' + str(self)) > > TIMEOUT: Timeout exceeded. > > "Timeout" means that the "pexpect" partner did not respond sufficiently > fast. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Thread getting stuck\hang
Hi Team, I have python code that creates thread.Sometimes it works, sometimes it gets stuck once its finish its execution part. still not yet cannot find any difference between when it works or when it gets stuck. Please help. sniffer1 = threading.Thread(target=validate_traffic_stats_dy,args=(FT_item_dy,RT_item_dy,forward_path_list_dy,return_path_list_dy,nat_type_list_dy,pkt_dy_1,)) sniffer2 = threading.Thread(target=validate_traffic_stats_st,args=(FT_item_st,RT_item_st,forward_path_list_st,return_path_list_st,nat_type_list_st,pkt_st,)) sniffer1.start() sniffer2.start() sniffer3 = threading.Thread(target=delete_new_dynamic_nat_conf) sniffer3.start() sniffer1.join() sniffer2.join() sniffer3.join() Thanks, Iranna m -- https://mail.python.org/mailman/listinfo/python-list
Re: Thread getting stuck\hang
) count_dy_out_Rx += int(returndict['txrxstats']['rx'][data] ) global count_dy_Tx,count_dy_in_Tx,count_dy_out_Tx count_dy_Tx = 0 count_dy_in_Tx = 0 count_dy_out_Tx = 0 for data in returndict['txrxstats']['tx'].keys(): if "TI05" in data: count_dy_Tx += int(returndict['txrxstats']['tx'][data] ) count_dy_in_Tx += int(returndict['txrxstats']['tx'][data] ) elif "TI66" in data: count_dy_Tx += int(returndict['txrxstats']['tx'][data] ) count_dy_out_Tx += int(returndict['txrxstats']['tx'][data] ) for forward_ip_list,return_ip_list,nat_type in zip (forward_path_list,return_path_list,nat_type_list): global_stats_list = [] for translation_ip,return_ip in zip (forward_ip_list,return_ip_list): output=listtostr(returndict['txrxstats']['rx']) if re.search('{0}'.format(translation_ip),output,re.I): pass else: global_stats_list.append(translation_ip) if global_stats_list == []: log.info('itgen traffic validation for {0} forward path - verified'.format(nat_type)) forward_ip_list = [] return_ip_list = [] else: log.error('{0} forward path itgen verification failed'.format(nat_type)) flag2 = 0 return flag2 log.info("Trafiic validation for NAT return path starting") returndict = itgen_explorer.startTrafficFlows(testbeddict, log,'-traffic_items {0} -pktcount 1000 -profile {1}'.format(RT_item,itgenProfile)) time.sleep(5) local_stats_list = [] for forward_ip_list,return_ip_list,nat_type in zip (forward_path_list,return_path_list,nat_type_list): local_stats_list = [] for translation_ip,return_ip in zip (forward_ip_list,return_ip_list): output=listtostr(returndict['txrxstats']['rx']) if re.search('{0}'.format(return_ip),output,re.I): pass else: local_stats_list.append(return_ip) if local_stats_list == []: log.info('itgen traffic validation for {0} return path - verified'.format(nat_type)) forward_ip_list = [] return_ip_list = [] else: log.error('{0} return path itgen verification failed'.format(nat_type)) flag2 = 0 return flag2 return flag2,count_dy_Rx,count_dy_in_Rx,count_dy_out_Rx,count_dy_Tx,count_dy_in_Tx,count_dy_out_Tx *def* *delete_new_dynamic_nat_conf():* global pool_dy_in_new,acl_name_dy_in_new,pool_name_dy_in_new direction_in = 'inside' log.info("Deleting Dynamic NAT new entries") delete_dynamic_nat_conf(uut2_hdl2, direction_in, acl_name_dy_in_new, pool_name_dy_in_new, ) #remove pool and acl name log.info('Removing access-list') deleteACL(uut2_hdl2, log, '-type {0} -name {1}'.format('ip', acl_name_dy_in_new)) log.info('Unconfiguring pool on UUT') add_remove_pool(uut2_hdl2, 'unconfigure', pool_dy_in_new) return 1 On Thu, Apr 27, 2017 at 9:04 PM, Dennis Lee Bieber wrote: > On Thu, 27 Apr 2017 19:48:24 +0530, Iranna Mathapati > declaimed the following: > > >Hi Team, > > > >I have python code that creates thread.Sometimes it works, sometimes it > >gets stuck once its finish its execution part. still not yet cannot find > >any difference between when it works or when it gets stuck. Please help. > > > > > >sniffer1 = > >threading.Thread(target=validate_traffic_stats_dy, > args=(FT_item_dy,RT_item_dy,forward_path_list_dy,return_ > path_list_dy,nat_type_list_dy,pkt_dy_1,)) > > > >sniffer2 = > >threading.Thread(target=validate_traffic_stats_st, > args=(FT_item_st,RT_item_st,forward_path_list_st,return_ > path_list_st,nat_type_list_st,pkt_st,)) > > > >sniffer1.start() > > > >sniffer2.start() > > > >sniffer3 = threading.Thread(target=delete_new_dynamic_nat_conf) > > > >sniffer3.start() > > > > So where is the code for the three thread functions? Where do the > various argument values come from? > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Thread getting stuck\hang
Thanks Dennis, On Fri, Apr 28, 2017 at 5:06 AM, Dennis Lee Bieber wrote: > On Thu, 27 Apr 2017 22:16:06 +0530, Iranna Mathapati > declaimed the following: > > >Hi Dennis, > > > >all function arguments declare as global and pass it to the function. > > > >All three thread is completed the execution part and after completion of > >execution its stuck/hang the programme. > > > >*def > >validate_traffic_stats_st(FT_item,RT_item,forward_path_ > list,return_path_list,nat_type_list,pkt_st)* > >: > >global flag1 > >flag1 = 1 > > > Dangerous usage... Threads should not rely on writing to globals > unless > they surround all accesses to the global with a mutual exclusion lock -- OR > there is only one thread allowed to ever write to the global (a common > usage is for the main program to set a flag that signals threads to exit, > and the threads periodically read the flag to see if it has been set). > > > > >log.error('{0} forward path itgen verification > >failed'.format(nat_type)) > >flag1 = 0 > >return flag1 > > threads do not "return" data, they just exit > > > >return > >flag1,count_st_Rx,count_st_in_Rx,count_st_out_Rx,count_ > st_Tx,count_st_in_Tx,count_st_out_Tx > > > > Ditto -- all those items specified in the return are just being > dumped > on the floor. > > > Recommendations: GET RID OF ALL GLOBAL VARIABLES. If you MUST have > shared global variables, you MUST surround access to the variables with > mutual exclusion locks -- otherwise you run the risk of counters and lists > getting out of sync. I'd also suggest compressing sharing down to single > objects, not half a dozen ad-hoc names. That is: > > class St_Record(object): > def __init__(self): > self.flag1 = True > self.count_st_Rx = 0 > self.count_st_in_Rx = 0 > self.count_st_out_Rx = 0 > self.whatever = suitableInitValue > > etc. for any other item needed for "st" > > Do a similar class for the "dy" > > > Instanciate one instance of each > > st_rec = St_Record() > ... > > And inside the relevant threads simply access as > > st_rec.count_st_Rx += ... > > Assuming these are only used by one thread (and the main program after they > end) you don't even need to declare them global. Python will find the > instances at the module level, and one can mutate the instance (ie; the > contents) without needing to declare global. > > > "Lockup" of the program implies dead-lock, which usually means race > conditions for the references to data objects between threads, or improper > use of mutual exclusion. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Thread getting stuck\hang
Hi Dennis, Two threads(_st and _dy targets) sharing the same user define function at the same time...This is the reason for hang/stuck? in both the thread ,we are calling same user define function (itgen_explorer.startTrafficFlows) and greping the values from return function ,using it in main function. On Fri, Apr 28, 2017 at 5:06 AM, Dennis Lee Bieber wrote: > On Thu, 27 Apr 2017 22:16:06 +0530, Iranna Mathapati > declaimed the following: > > >Hi Dennis, > > > >all function arguments declare as global and pass it to the function. > > > >All three thread is completed the execution part and after completion of > >execution its stuck/hang the programme. > > > >*def > >validate_traffic_stats_st(FT_item,RT_item,forward_path_ > list,return_path_list,nat_type_list,pkt_st)* > >: > >global flag1 > >flag1 = 1 > > > Dangerous usage... Threads should not rely on writing to globals > unless > they surround all accesses to the global with a mutual exclusion lock -- OR > there is only one thread allowed to ever write to the global (a common > usage is for the main program to set a flag that signals threads to exit, > and the threads periodically read the flag to see if it has been set). > > > > >log.error('{0} forward path itgen verification > >failed'.format(nat_type)) > >flag1 = 0 > >return flag1 > > threads do not "return" data, they just exit > > > >return > >flag1,count_st_Rx,count_st_in_Rx,count_st_out_Rx,count_ > st_Tx,count_st_in_Tx,count_st_out_Tx > > > > Ditto -- all those items specified in the return are just being > dumped > on the floor. > > > Recommendations: GET RID OF ALL GLOBAL VARIABLES. If you MUST have > shared global variables, you MUST surround access to the variables with > mutual exclusion locks -- otherwise you run the risk of counters and lists > getting out of sync. I'd also suggest compressing sharing down to single > objects, not half a dozen ad-hoc names. That is: > > class St_Record(object): > def __init__(self): > self.flag1 = True > self.count_st_Rx = 0 > self.count_st_in_Rx = 0 > self.count_st_out_Rx = 0 > self.whatever = suitableInitValue > > etc. for any other item needed for "st" > > Do a similar class for the "dy" > > > Instanciate one instance of each > > st_rec = St_Record() > ... > > And inside the relevant threads simply access as > > st_rec.count_st_Rx += ... > > Assuming these are only used by one thread (and the main program after they > end) you don't even need to declare them global. Python will find the > instances at the module level, and one can mutate the instance (ie; the > contents) without needing to declare global. > > > "Lockup" of the program implies dead-lock, which usually means race > conditions for the references to data objects between threads, or improper > use of mutual exclusion. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Thread getting stuck\hang
Hi Dennis, Two threads(_st and _dy targets) sharing the same user define function at the same time...This is the reason for hang/stuck? in both the thread ,we are calling same user define function (itgen_explorer.startTrafficFlows) and greping the values from return function ,using it in main function. script was hang after completion of the program only . On Fri, Apr 28, 2017 at 2:42 PM, Iranna Mathapati wrote: > Hi Dennis, > > Two threads(_st and _dy targets) sharing the same user define function at > the same time...This is the reason for hang/stuck? > > in both the thread ,we are calling same user define function > (itgen_explorer.startTrafficFlows) and greping the values from return > function ,using it in main function. > > > On Fri, Apr 28, 2017 at 5:06 AM, Dennis Lee Bieber > wrote: > >> On Thu, 27 Apr 2017 22:16:06 +0530, Iranna Mathapati >> declaimed the following: >> >> >Hi Dennis, >> > >> >all function arguments declare as global and pass it to the function. >> > >> >All three thread is completed the execution part and after completion of >> >execution its stuck/hang the programme. >> > >> >*def >> >validate_traffic_stats_st(FT_item,RT_item,forward_path_list >> ,return_path_list,nat_type_list,pkt_st)* >> >: >> >global flag1 >> >flag1 = 1 >> > >> Dangerous usage... Threads should not rely on writing to globals >> unless >> they surround all accesses to the global with a mutual exclusion lock -- >> OR >> there is only one thread allowed to ever write to the global (a common >> usage is for the main program to set a flag that signals threads to exit, >> and the threads periodically read the flag to see if it has been set). >> >> >> >> >log.error('{0} forward path itgen verification >> >failed'.format(nat_type)) >> >flag1 = 0 >> >return flag1 >> >> threads do not "return" data, they just exit >> >> >> >return >> >flag1,count_st_Rx,count_st_in_Rx,count_st_out_Rx,count_st_ >> Tx,count_st_in_Tx,count_st_out_Tx >> > >> >> Ditto -- all those items specified in the return are just being >> dumped >> on the floor. >> >> >> Recommendations: GET RID OF ALL GLOBAL VARIABLES. If you MUST have >> shared global variables, you MUST surround access to the variables with >> mutual exclusion locks -- otherwise you run the risk of counters and lists >> getting out of sync. I'd also suggest compressing sharing down to single >> objects, not half a dozen ad-hoc names. That is: >> >> class St_Record(object): >> def __init__(self): >> self.flag1 = True >> self.count_st_Rx = 0 >> self.count_st_in_Rx = 0 >> self.count_st_out_Rx = 0 >> self.whatever = suitableInitValue >> >> etc. for any other item needed for "st" >> >> Do a similar class for the "dy" >> >> >> Instanciate one instance of each >> >> st_rec = St_Record() >> ... >> >> And inside the relevant threads simply access as >> >> st_rec.count_st_Rx += ... >> >> Assuming these are only used by one thread (and the main program after >> they >> end) you don't even need to declare them global. Python will find the >> instances at the module level, and one can mutate the instance (ie; the >> contents) without needing to declare global. >> >> >> "Lockup" of the program implies dead-lock, which usually means >> race >> conditions for the references to data objects between threads, or improper >> use of mutual exclusion. >> -- >> Wulfraed Dennis Lee Bieber AF6VN >> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > -- https://mail.python.org/mailman/listinfo/python-list
Re: Thread getting stuck\hang
Hi Dennis, My requirement is like,i want to send the static and dynamic traffic together.while traffic sending i want to delete some config from device. st and dy both the targets want to be run at the same time. On Fri, Apr 28, 2017 at 6:10 PM, Dennis Lee Bieber wrote: > On Fri, 28 Apr 2017 14:42:33 +0530, Iranna Mathapati > declaimed the following: > > >Hi Dennis, > > > >Two threads(_st and _dy targets) sharing the same user define function at > >the same time...This is the reason for hang/stuck? > > > >in both the thread ,we are calling same user define function > >(itgen_explorer.startTrafficFlows) and greping the values from return > >function ,using it in main function. > > > > While the threads will have their own stacks, meaning function > local > data should be separate, if that common function is written anything like > the st/dy threads (that is, full of "global" declarations) anything could > be happening. > > > Given that your original sample main logic basically just started > three > threads and almost immediately waits for them to complete by using .join(), > I have to wonder just why you are using threads at all. > > Due to the GIL, even on a multi-core processor, only one thread can > actually do anything at a time (threads work great when they spend most of > their time waiting for I/O operations to complete, but are terrible if > trying to do heavy number crunching). If you don't have lots of blocking > I/O, the thread switching will actually make using threads take more time > then just calling the functions one after the other. > > From your original post, what happens if you replace: > > >sniffer1 = > >threading.Thread(target=validate_traffic_stats_dy, > args=(FT_item_dy,RT_item_dy,forward_path_list_dy,return_ > path_list_dy,nat_type_list_dy,pkt_dy_1,)) > >sniffer2 = > >threading.Thread(target=validate_traffic_stats_st, > args=(FT_item_st,RT_item_st,forward_path_list_st,return_ > path_list_st,nat_type_list_st,pkt_st,)) > >sniffer1.start() > >sniffer2.start() > >sniffer3 = threading.Thread(target=delete_new_dynamic_nat_conf) > >sniffer3.start() > >sniffer1.join() > >sniffer2.join() > >sniffer3.join() > > with just the inline calls: > > validate_traffic_stats_dy(the arg list) > validate_traffic_stats_st(its arg list) > delete_new_dynamic_nat_conf() > > That should run them in sequence, with no chance for conflicts > between > shared state. > > If you still get erratic hanging, you have a logic problem > somewhere > else in the program other than a shared state deadlock. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
how to share/access variables from multiprocessing target function
*Hi team,* *How to access the multiprocessing target function variables across the main program. * *def sending_static_traffic(FT_item_st,RT_item_st,pkt_st)*: log.info('Starting Static NAT forward Traffic Test...') global returndict_st_FP,returndict_st_RP <
Re: how to share/access variables from multiprocessing target function
Can you please elaborate in my case(means above code)i tried with manager still hitting issue. Thanks, On Wed, May 3, 2017 at 8:14 PM, eryk sun wrote: > On Wed, May 3, 2017 at 2:04 PM, Iranna Mathapati > wrote: > > how to share/access the " global returndict_st_FP,returndict_st_RP" > target > > function variables acors the main program.. > > You can share a dict using a Manager. > > https://docs.python.org/3/library/multiprocessing.html#managers > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
how to grep
Hi Team, How to grep values from below out put string. pattern should include "Fabric Module". grepping Fabric module values only str = ''' 22 0Fabric Module J8N-C9508-FM ok 24 0Fabric ModuleJ8N-C9508-FM ok 26 0Fabric ModuleJ8N-C9508-FM ok 22 016-slot Fabric Module J8N-C9516-FM-Eok 24 016-slot Fabric Module J8N-C9516-FM-Eok''' output = [22,24,26,22,24] Thanks Iranna M -- https://mail.python.org/mailman/listinfo/python-list