본문 바로가기

Python53

string을 원하는 width로 자르고 싶을때 python 내부 함수로 string을 원하는 width로 자르기 import textwrap result: List[str] = textwrap.wrap(string, max_width) >>> import textwrap >>> textwrap.wrap("abcdefghijklmn", 3) ['abc', 'def', 'ghi', 'jkl', 'mn'] 2020. 6. 26.
RabbitMQ - python RabbitMQ producer, consumer 구현 rabbit mq process """Message Queue.""" import logging import pika class MessageQueue: """ Message Queue. mq """ LOGGER = logging.getLogger(__name__) def __init__(self, name: str, url: str) -> None: """ Init. name str: queue name url str: radditMQ url with id, password "amqp://relay:relay1234@localhost/vh1" """ self.key = name self.url = url self.conn = None self.ch.. 2020. 6. 25.
python 에서 redis를 메시지 queue로 사용 파이썬에서 redis를 message queue로 구현 redis class - redis_queue.py """RedisQueue class""" import redis class RedisQueue(object): """ Redis Lists are an ordered list, First In First Out Queue Redis List pushing new elements on the head (on the left) of the list. The max length of a list is 4,294,967,295 """ def __init__(self, name, max_size, **redis_kwargs): self.key = name self.max_size = max_size self.. 2020. 6. 19.
time 명령어를 이용한 간단한 처리 시간 측정 time 명령어를 이용한 간단한 시간 측정 $ /usr/bin/time -p python test_1.py real 64.38 # 경과된 시간 user 63.65 # cpu가 커널함수 외 작업에 소비한 시간 sys 0.36 # 커널함수를 수행하는데 소비한 시간 좀 더 자세한 정보는 -lp 옵션을 사용한다 $ /usr/bin/time -lp python test_1.py real 64.20 user 63.71 sys 0.28 7098368 maximum resident set size 0 average shared memory size 0 average unshared data size 0 average unshared stack size 2444 page reclaims 40 page faults 0 s.. 2020. 6. 17.
파이썬 정규식(regular expression:regex) 사용 - 일부만 추출 파이썬에서 정규식 사용 정규식으로 찾고 일부만 추출하기 >>> import re >>> _str=" 65 0 0 -50 243 323 Tm\n asdfasdf" # 정규식에서 `()`로 싸여진 곳이 `group` >>> matches = re.finditer(r"^\d+ \d+ \d+ \-\d+ (\d+) \d+ Tm$",b,re.MULTILINE) >>> for match in matches: ... print(match.group()) ... group_num = len(match.groups()) ... print(match.group(group_num)) ... 65 0 0 -50 243 323 Tm 243 2020. 6. 15.
파일이름이나 프로세스 명으로 프로세스 죽이기(kill) 프로세스 명으로 프로세스 죽이기 nohup으로 프로세스 돌렸을 때 아래 명령어에서 manage.py를 죽이는 것 manage.py 만 원하는 이름으로 바꾸고 사용하면 된다 $ kill -9 `ps aux |grep manage.py |grep -v grep |awk '{ print $2 }'` 2020. 6. 13.