분류 전체보기 (667) 썸네일형 리스트형 [Python] Multiprocessing(2) - Naming, Parallel processing 멀티 프로세스를 그룹으로 실행하는 샘플코드 from multiprocessing import Process, current_process import os import random import time # 실행 방법 def square(n): # 랜덤 sleep time.sleep(random.randint(1, 3)) process_id = os.getpid() process_name = current_process().name # 제곱 result = n * n # 정보 출력 print(f">> Process Name: {process_name}, Process ID: {process_id}") print(f"*** Result of {n} square : {result}") if __name__ =.. [Python] Multiprocessing(1) - Join, is_alive 프로세스 생성방법 - 기초 from multiprocessing import Process import time import logging # 프로세스 실행 함수 def proc_func(name): # 프로세스에서는 로깅 방법을 각각 설정해야 함. # Logging format 설정 format = "%(asctime)s: %(message)s" logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S") logging.info("Sub-Process {}: starting".format(name)) logging.info("Sub-Process {}: starting".format(name)) time.sleep(3) loggi.. [Python] Thread(5) - Producer and Consumer Using Queue 큐를 이용한 생산자 소비자 구조의 스레드 import concurrent.futures import logging import queue import random import threading import time # 생산자 def producer(queue, event): ''' 네트워크 대기 상태라 가정(서버) ''' while not event.is_set(): message = random.randint(1,101) logging.info('Producer got message: {}'.format(message)) queue.put(message) logging.info('Producer received event Exiting') # 소비자 def consumer(queue, event): '.. [Python] Thread(4) - Lock, Unlock 공유자원을 Lock & unLock 하는 2가지 방식에 대한 정리. import logging from concurrent.futures import ThreadPoolExecutor import time import threading class FakeDataStore: # 공유 변수(value) def __init__(self): # 스택영역 self.value = 0 self._lock = threading.Lock() # 변수 업데이트 함수 def update(self, n): logging.info('Thread ***{}: starting update'.format(n)) # 뮤텍스 & Lock 등 동기화(Thraed synchronization 필요) # Lock 획득 / 방법1 self._.. [Python] Thread(3) - ThreadPoolExecutor import logging from concurrent.futures import ThreadPoolExecutor import time def task(name, n): logging.info('***Sub-Thread %s: starting', name) result = 0 for i in range(n): result += i logging.info('***Sub-Thread %s: finished result: %d', name, result) return result def main(): # Logging format 설정 format = "%(asctime)s: %(message)s" logging.basicConfig(format=format, level=logging.INFO, datefm.. [Python] Thread(2) - DeamonThread """ DaemonThread(데몬스레드) (1).백그라운드에서 실행 (2).메인스레드 종료시 즉시 종료 - 데몬스레드의 특징 (3).주로 백그라운드 무한 대기 시 이벤트 발생시 실행하는 부분 담당 -> JVM(가비지 콜렉터), 자동저장 (4).일반 스레드는 작업 종료시 까지 실행 """ import logging import threading import time # 스레드 실행 함수 def thread_func(name, d): logging.info("Sub-Thread %s: starting", name) for i in d: print("***Sub-Thread {}: {}".format(name, i)) # pass logging.info("Sub-Thread %s: finishing", na.. [Python] Thread(1) - Basic import logging import threading import time # 스레드 실행 함수 def thread_func(name): logging.info("**Sub-Thread %s: starting", name) time.sleep(3) logging.info("**Sub-Thread %s: finishing", name) # 메인 영역 if __name__ == "__main__": # Logging format 설정 format = "%(asctime)s: %(message)s" logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S") logging.info("Main-Thread : before creatin.. [Dart] Null Safety 널을 할당 가능하게 하려면 ? 기호를 추가하면 된다. void main() { int? a; a = null; print('a is $a.'); String? name; name = null; print('you name is $name'); } ----------------------------[result] a is null. you name is null 리스트를 사용하는 경우 '?' 위치 void main() { List aListOfStrings = ['one', 'two', 'three']; // 리스트 멤버가 없는경우는 , 빈 리스트 할당으로 ? 대체 가능 List aNullableListOfStrings = []; // 리스트 멤버가 없는경우는 , 타입 뒤에 ? 위치 List? aNulla.. 이전 1 ··· 79 80 81 82 83 84 다음