<s> from gevent import monkey ; monkey . patch_all ( ) <EOL> from gevent . event import Event <EOL> from gevent import sleep , spawn <EOL> from django . core . mail . backends . smtp import EmailBackend as DjangoEmailBackend <EOL> class EmailBackend ( DjangoEmailBackend ) : <EOL> """<STR_LIT>""" <EOL> _pending_sent = [ ] <EOL> _ready_sent = Event ( ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> spawn ( self . __mail_proc ) <EOL> super ( EmailBackend , self ) . __init__ ( * args , ** kwargs ) <EOL> def __mail_proc ( self ) : <EOL> self . _ready_sent . wait ( ) <EOL> super ( EmailBackend , self ) . send_messages ( self . _pending_sent ) <EOL> def send_messages ( self , email_messages ) : <EOL> if not email_messages : <EOL> return <NUM_LIT:0> <EOL> self . _pending_sent = email_messages <EOL> self . _ready_sent . set ( ) <EOL> return len ( email_messages ) </s>
