
# -*- coding: utf-8 -*-
from django.conf import settings
if settings.DATABASE_ENGINE=='pool':
	settings.DATABASE_ENGINE=settings.POOL_DATABASE_ENGINE

from django.core.management.base import BaseCommand, CommandError
import os
import time
import sys
from mysite.iclock.constant import REALTIME_EVENT, DEVICE_POST_DATA
from mysite.iclock.devview import write_data

class Command(BaseCommand):
    option_list = BaseCommand.option_list + ()
    help = "Starts write data process."
    args = ''

    def handle(self, *args, **options):
		from mysite.iclock.models.model_cmmdata import process_writedata
		from django.db import connection as conn
		while True:
			process_writedata()#30分钟后会退出
			try:
				#退出的时候防止是断网，不断开连接而不能处理数据，所以关闭该连接
				cur=conn.cursor()
				cur.close()
				conn.close()
			except:
				pass
