분류 전체보기 (667) 썸네일형 리스트형 [Dart] Class - 상속/Inheritance void main() { House house1 = new House(4, 2); house1.aboutFloors(); house1.aboutRooms(); print('------------- APT -------------'); Apt apt1 = new Apt(5, 3, 'Rome'); apt1.aboutFloors(); apt1.aboutRooms(); apt1.aboutName(); print('------------- Villa -------------'); Villa villa1 = new Villa(1, 2, 'Milano'); villa1.aboutFloors(); villa1.aboutRooms(); villa1.aboutName(); } class House { // private .. [Dart] Class - getter, setter void main() { House house1 = new House(4,2); house1.aboutHouse(); print(house1.rooms); house1.rooms = 10; house1.aboutHouse(); } class House { // private variable int _rooms; int _floors; House(this._rooms, this._floors); void aboutHouse(){ print('This house has $_floors floors and $_rooms rooms.'); } int get rooms{ return this._rooms; } set rooms(int room){ this._rooms = room; } } -------------.. [Dart] Class - 선언 및 생성자 선언 및 생성자 void main() { House house1 = new House(4,2); house1.aboutHouse(); } class House { final int? rooms; final int? floors; House(this.rooms, this.floors); void aboutHouse(){ print('This house has $floors floors and $rooms rooms.'); } } --------------------------------------------[result] This house has 2 floors and 4 rooms. 다른 스타일 생성자 void main() { House house1 = new House(4,2); house1.abou.. [Python] 병행성(Concurrency) - Futures(2) 2가지 패턴 실습 concurrent.futures - wait, as_completed import os import time from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor, wait, as_completed WORK_LIST = [100000000, 10000000, 1000000, 100000] # 동시성 합계 계산 메인 함수 # 누적 합계 함수(제레네이터) def sum_generator(n): return sum(n for n in range(1, n+1)) # wait - 모든 작업이 끝날때까지 기다림 # as_completed - 먼저 끝난 작업결과를 반환함 def main(): # Worker Count wor.. [Python] 병행성(Concurrency) - Futures(1) Futures 동시성 비동기 작업 실행 지연시간(Block) CPU 및 리소스 낭비 방지 -> (File)Network I/O 관련 작업 -> 동시성 활용 권장 비동기 작업과 적합한 프로그램일 경우 압도적으로 성능 향상 futures : 비동기 실행을 위한 API를 고수준으로 작성 -> 사용하기 쉽도록 개선 concurrent.Futures 1. 멀티스레딩/멀티프로세싱 API 통일 -> 매우 사용하기 쉬움 2. 실행중이 작업 취소, 완료 여부 체크, 타임아웃 옵션, 콜백추가, 동기화 코드 매우 쉽게 작성 -> Promise 개념 GIL : 두 개 이상의 스레드가 동시에 실행 될 때 하나의 자원을 엑세스 하는 경우 -> 문제점을 방지하기 위해 GIL 실행 , 리소스 전체에 락이 걸린다. -> Context.. [Python] 병행성(Concurrency) - Coroutine 흐름제어 병행성(Concurrency) : 한 컴퓨터가 여러 일을 동시에 수행 -> 단일 프로그램안에서 여러일을 쉽게 해결 병렬성(Parallelism) : 여러 컴퓨터가 여러 작업을 동시에 수행 -> 속도 코루틴(Coroutine) : 단일(싱글) 스레드, 스택을 기반으로 동작하는 비동기 작업 스레드 : OS 관리, cpu 코어에서 실시간, 시분할 비동기 작업 -> 멀티스레드 yield, send : 메인 서브 코루틴 제어, 상태, 양방향 전송 yield from 서브루틴 : 메인루틴에서 호출 -> 서브루틴에서 수행(흐름제어) 코루틴 : 루틴 실행 중 중지 -> 동시성 프로그래밍 코루틴 : 스레드에 비해 오버헤드 감소 스레드 : 싱글스레드 -> 멀티스레드 -> 복잡 -> 공유되는 자원 -> 교착 상태 .. [Python] 병행성(Concurrency) - generator Iterator, Generator - 값을 차례대로 가져올 수 있음 # Generator Ex1, yield 키워드가 있으면 제너레이터로 처리됨 def generator_ex1(): print('start') yield 'A_Point' print('continue') yield 'B_Point' print('end') temp = iter(generator_ex1()) print(temp) print(next(temp)) print(next(temp)) print(next(temp)) ==> 여기서 예외처리 발생. --------------------------------------------[result] < generator object generator_ex1 at 0x000002B83203EE.. [Python] 병행성(Concurrency) - basic iterable 객체 - 반복 가능한 객체 iterator 객체 - 값을 차례대로 꺼낼 수 있는 객체 iterable 객체 # 반복 가능한 이유? -> 내부적으로 iter() 함수 호출 t = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # for 반복 for c in t: print(c, end=' ') --------------------------------------------[result] A B C D E F G H I J K L M N O P Q R S T U V W X Y Z iterator 객체 a=t.__iter__() print([next(a) for _ in range(len(t))]) # while 반복 w = iter(t) while True: try: print(next.. 이전 1 ··· 75 76 77 78 79 80 81 ··· 84 다음