<s> import time <EOL> import io <EOL> import threading <EOL> import picamera <EOL> class Camera ( object ) : <EOL> thread = None <EOL> frame = None <EOL> last_access = <NUM_LIT:0> <EOL> def initialize ( self ) : <EOL> if Camera . thread is None : <EOL> Camera . thread = threading . Thread ( target = self . _thread ) <EOL> Camera . thread . start ( ) <EOL> while self . frame is None : <EOL> time . sleep ( <NUM_LIT:0> ) <EOL> def get_frame ( self ) : <EOL> Camera . last_access = time . time ( ) <EOL> self . initialize ( ) <EOL> return self . frame <EOL> @ classmethod <EOL> def _thread ( cls ) : <EOL> with picamera . PiCamera ( ) as camera : <EOL> camera . resolution = ( <NUM_LIT> , <NUM_LIT> ) <EOL> camera . hflip = True <EOL> camera . vflip = True <EOL> camera . start_preview ( ) <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> stream = io . BytesIO ( ) <EOL> for foo in camera . capture_continuous ( stream , '<STR_LIT>' , <EOL> use_video_port = True ) : <EOL> stream . seek ( <NUM_LIT:0> ) <EOL> cls . frame = stream . read ( ) <EOL> stream . seek ( <NUM_LIT:0> ) <EOL> stream . truncate ( ) <EOL> if time . time ( ) - cls . last_access > <NUM_LIT:10> : <EOL> break <EOL> cls . thread = None </s>
