IPython.embed()
을 파이썬 스크립트로 호출 할 때 시간 초과가있는 방법이 있습니까? 여러 장소에서 IPython.embed()
에 대해 중지하는 스크립트가 있다고 가정 해보십시오. 사용자가 시간에 응답하지 않으면 어떻게 스크립트를 계속 사용할 수 있습니까?IPython을 호출 할 때 시간 초과 embed()
답변
이 질문에 대한 답변은 아니지만 원하는 내용으로는 충분합니다.
나는- https://stackoverflow.com/a/23098294/1490584에서 약간의 크로스 플랫폼의 키 제한 시간 코드를 사용하고,
- https://stackoverflow.com/a/5047058/1490584
는 IPython.embed()를해야하는 경우 사용자가 시간 창 내에서 결정하도록 다음과 같이 호출해야합니다.
import time
import IPython
try:
from msvcrt import kbhit
except ImportError:
import termios, fcntl, sys, os
def kbfunc():
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
try:
while True:
try:
c = sys.stdin.read(1)
return c.decode()
except IOError:
return False
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
else:
import msvcrt
def kbfunc():
#this is boolean for whether the keyboard has bene hit
x = msvcrt.kbhit()
if x:
#getch acquires the character encoded in binary ASCII
ret = msvcrt.getch()
return ret.decode()
else:
return False
def wait_for_interrupt(waitstr=None, exitstr=None, countdown=True, delay=3):
if waitstr is not None: print(waitstr)
for i in range(delay*10):
if countdown and i%10 ==0 : print('%d'%(i/10 + 1), end='')
elif countdown and (i+1)%10 ==0: print('.')
elif countdown : print('.', end='')
key = kbfunc()
if key: return key
time.sleep(0.1)
if exitstr is not None: print(exitstr)
return False
if __name__ == "__main__":
#wait_for_interrupt example test
if wait_for_interrupt('wait_for_interrupt() Enter something in the next 3 seconds', '... Sorry too late'):
IPython.embed()
#begin the counter
number = 1
#interrupt a loop
while True:
#acquire the keyboard hit if exists
x = kbfunc()
#if we got a keyboard hit
if x != False and x == 'i':
#we got the key!
IPython.embed()
#break loop
break
else:
#prints the number
print(number)
#increment, there's no ++ in python
number += 1
#wait half a second
time.sleep(0.5)
흥미로운 솔루션! =) – elias
'c = sys.stdin.read (1)'행 다음에'F2 '와 같은 키가 눌려지면'stdin'에 데이터가 남아있어 트리거가 실행되는 동안 오류가 발생했습니다 다음의'wait_for_interrupt()'. 의도하지 않은 버그를 도입하지 않고이를 해결하는 방법은 무엇입니까? –
그리고'wait_for_interrupt()'가 호출되기 전에'stdin'이 이미 데이터를 가지고있는 경우는 어떨까요? 'stdin'을 가정하거나'wait_for_interrupt()'를'context_manager' ('with' 문)와 함께 사용해서 자체적으로 /'stdin 다음에 준비하고 클린업해야한다. '? –
- 1. `eval` 호출 시간 초과
- 2. 다른 스레드에서 호출 할 때 쿼리 시간 초과
- 3. .NET에서 함수를 호출 할 때 시간 초과 값 설정
- 4. Java에서 ResultSet에서 next를 호출 할 때 시간 초과 예외가 발생했습니다.
- 5. DBus 동기 호출 시간 초과
- 6. 시간 초과 후 시간 초과가없는 urlopen 호출
- 7. Jquery ajax 호출 시간 초과.
- 8. xml을 다운로드 할 때 curl 시간 초과
- 9. nusoap이 PHP 응용 프로그램에서 웹 서비스를 호출 할 때 시간 초과 문제를 처리 할 때
- 10. 아음속 저장 프로 시저 호출 시간 초과
- 11. 시간 초과 명령 후 오류 호출 방지하기
- 12. 검색을 실행할 때 시간 초과.
- 13. Heroku로 밀 때 시간 초과
- 14. 세션 시간 초과 때 폴링
- 15. 시간 초과
- 16. 시간 초과 후 CPP 호출 기능
- 17. 파이프 된 명령의 시간 초과 호출
- 18. PageMethod 기본 시간 초과
- 19. Telerik Radscheduler 웹 서비스 호출 시간 초과
- 20. 람다 콜백 호출 후 시간 초과
- 21. 처음 호출 할 때마다 어댑터 호출이 끊어지고 있습니다 (시간 초과)
- 22. HttpWebResponse Google Places API 호출 시간 초과
- 23. NSOperationQueue에서 동기 서버 호출 시간 초과
- 24. 웹 서비스 호출 시간 초과 문제
- 25. 튜닝 소켓 연결 호출 시간 초과 연결
- 26. 시간 초과 발생 후 메소드 호출
- 27. WSO2 ESB 차단 호출 시간 초과
- 28. Simple Meteor http 호출 시간 초과
- 29. 자동 연결 시간 초과 (세션 시간 초과)
- 30. 회원 시간 초과 및 세션 시간 초과
현재 API 그러나 디버깅을 위해 사용할 때 유용 할 수있는 팁은''% kill_embedded'' 매크로입니다 :''IPython.embed()''에서 사용하면 다른 세션을 다시 열지 않을 것입니다. – elias
고마워, 그건 편리한 트릭이긴하지만 내가 찾고있는 것이 아니다. –
입력 타임 아웃 솔루션 ('Type 'i/I')을 사용하여 IPython 모드로 들어간다 : \ n .... 1 \ n .... 2 \ n .... 3 \ n ... .4 \ n .... 5 \ nSorry too late') 여기에 설명 된대로 http://stackoverflow.com/questions/1335507/keyboard-input-with-timeout-in-python –