Thanks for your reply. I guess you were right when I thought its getting hanged because it was actually working hard. So I moved out of windbg and ruunnng the script externally. To test I modified the code in this way.
from pykd import *
from pykd import *
pid = raw_input(' Enter PID >>> ')
d=attachProcess(int(pid))
print d
while 1:
dprintln('Hello!!')
r_o = dbgCommand('r')
dprintln(r_o)
step()
Here I should continuously get "Hello" and "r" command output in command prompt. I get for few instruction, but after sometime it stopped printing "Hello" and "r" command output. Here is my out putC:\Program Files (x86)\Debugging Tools for Windows (x86)\winext>python test.py
Enter PID >>> 6736
0
Hello!!
eax=7ef64000 ebx=00000000 ecx=00000000 edx=777cf8ea esi=00000000 edi=00000000
eip=7774000c esp=0f6dfa94 ebp=0f6dfac0 iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246
ntdll!DbgBreakPoint:
7774000c cc int 3
Hello!!
eax=7ef64000 ebx=00000000 ecx=00000000 edx=777cf8ea esi=00000000 edi=00000000
eip=7774000d esp=0f6dfa94 ebp=0f6dfac0 iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000244
ntdll!DbgBreakPoint+0x1:
7774000d c3 ret
Hello!!
eax=7ef64000 ebx=00000000 ecx=00000000 edx=777cf8ea esi=00000000 edi=00000000
eip=777cf926 esp=0f6dfa98 ebp=0f6dfac0 iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246
ntdll!DbgUiRemoteBreakin+0x3c:
777cf926 eb07 jmp ntdll!DbgUiRemoteBreakin+0x45 (777cf92f)
Hello!!
eax=7ef64000 ebx=00000000 ecx=00000000 edx=777cf8ea esi=00000000 edi=00000000
eip=777cf92f esp=0f6dfa98 ebp=0f6dfac0 iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246
ntdll!DbgUiRemoteBreakin+0x45:
777cf92f c745fcfeffffff mov dword ptr [ebp-4],0FFFFFFFEh ss:002b:0f6dfabc=00000000
Hello!!
eax=7ef64000 ebx=00000000 ecx=00000000 edx=777cf8ea esi=00000000 edi=00000000
eip=777cf936 esp=0f6dfa98 ebp=0f6dfac0 iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246
ntdll!DbgUiRemoteBreakin+0x4c:
777cf936 6a00 push 0
Hello!!
eax=7ef64000 ebx=00000000 ecx=00000000 edx=777cf8ea esi=00000000 edi=00000000
eip=777cf938 esp=0f6dfa94 ebp=0f6dfac0 iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246
ntdll!DbgUiRemoteBreakin+0x4e:
777cf938 e8df86fbff call ntdll!RtlExitUserThread (7778801c)
Hello!!
eax=00000000 ebx=00000000 ecx=00000000 edx=00000000 esi=00000000 edi=00000000
eip=77750096 esp=0f6dfa74 ebp=0f6dfa8c iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246
ntdll!ZwTerminateThread+0x12:
77750096 83c404 add esp,4
Is there anything extra I need to add to fix this.,