본문 바로가기

Programing/Python

Python subprocess Popen에서 좀비프로세스 방지 (zombie-processes 방지) python 배치안에서 Popen로 새로운 프로세스를 병렬적으로 실행하는데 부모 process가 멈춰있고 자식 프로세스들이 defunct되어 있는 것을 확인했다. 예를 들면 아래의 ls 실행 같이 말이다. subprocess.call( ('ps', '-l') )process.wait() print "after wait" subprocess.call( ('ps', '-l') ) Example output: $ python so2760652.py F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 S 501 21328 21326 0 80 0 - 1574 wait pts/2 00:00:00 bash 0 S 501 21516 21328 0 80 0 - 1434 wa.. 더보기
Python url download (파이썬 다운로드) 파이썬에서 url을 입력해서 download 받는 방법이다. www.python.org에서 html을 다운로드 해보자 import urllib # Get a file-like object for the Python Web site's home page. f = urllib.urlopen("http://www.python.org") # Read from the object, storing the page's contents in 's'. s = f.read() f.close() urllib를 import하고 urllib.urlopen() 함수를 호출하여 읽어들일 url을 나타내는 네트워크 객체를 생성하고 s라는 변수에 읽어 들인다. 그러면 끝 ! print s 라고 치면 읽어들인 것을 프린트 한다. url.. 더보기
Python CSV 파일을 xls 파일로 변환하기 / convering csv2xls using Python (csv to xls) csv파일을 xls파일료 변환하기 위해서 googling한 결과 http://sourceforge.net/projects/py-csv2xls/files/py-csv2xls/0.4.2/csv2xls-0.4.2.tgz/download 에서 python converter를 찾을 수 있었다. 다운받아서 압축을 풀면 csv2xls.py가 있다. main을 보니 아래와 같이 옵션이 있다. 실행해보쟈 def main(): parser = optparse.OptionParser() parser.add_option("-i", "--infile_names", dest="infile_names", default="", help="set infilenames") parser.add_option("-o", "--outfile_.. 더보기