当前位置: 首页>>代码示例>>Python>>正文


Python connections.close_all方法代码示例

本文整理汇总了Python中django.db.connections.close_all方法的典型用法代码示例。如果您正苦于以下问题:Python connections.close_all方法的具体用法?Python connections.close_all怎么用?Python connections.close_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.connections的用法示例。


在下文中一共展示了connections.close_all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def run(self):
        """
        Set up the live server and databases, and then loop over handling
        HTTP requests.
        """
        if self.connections_override:
            # Override this thread's database connections with the ones
            # provided by the main thread.
            for alias, conn in self.connections_override.items():
                connections[alias] = conn
        try:
            # Create the handler for serving static and media files
            handler = self.static_handler(_MediaFilesHandler(WSGIHandler()))
            self.httpd = self._create_server()
            # If binding to port zero, assign the port allocated by the OS.
            if self.port == 0:
                self.port = self.httpd.server_address[1]
            self.httpd.set_app(handler)
            self.is_ready.set()
            self.httpd.serve_forever()
        except Exception as e:
            self.error = e
            self.is_ready.set()
        finally:
            connections.close_all() 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:27,代码来源:testcases.py

示例2: run

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def run(self):
        """
        Sets up the live server and databases, and then loops over handling
        http requests.
        """
        if self.connections_override:
            # Override this thread's database connections with the ones
            # provided by the main thread.
            for alias, conn in self.connections_override.items():
                connections[alias] = conn
        try:
            # Create the handler for serving static and media files
            handler = self.static_handler(_MediaFilesHandler(WSGIHandler()))
            self.httpd = self._create_server()
            # If binding to port zero, assign the port allocated by the OS.
            if self.port == 0:
                self.port = self.httpd.server_address[1]
            self.httpd.set_app(handler)
            self.is_ready.set()
            self.httpd.serve_forever()
        except Exception as e:
            self.error = e
            self.is_ready.set()
        finally:
            connections.close_all() 
开发者ID:Yeah-Kun,项目名称:python,代码行数:27,代码来源:testcases.py

示例3: cancel_import_job

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def cancel_import_job(self, import_id):
        """Cancels an active import job.

        :param import_id: ID of the cancelled job.
        :type import_id: int or string holding an int
        """
        connections.close_all()
        import_dict = self._active_import_jobs.get(int(import_id), None)

        if import_dict:
            import_process = import_dict.get('process', None)
            if import_process:
                import_process.terminate()

            if import_dict['is_local'] is False:
                tear_down_import_directory(import_dict['directory'])

        try:
            dataset_import = self._dao.objects.get(pk=import_id)
            dataset_import.finished = True
            dataset_import.status = 'Cancelled'
            dataset_import.save()
        except:
            pass 
开发者ID:texta-tk,项目名称:texta,代码行数:26,代码来源:importer.py

示例4: _create_dataset_import

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def _create_dataset_import(self, parameters, request_user):
        """Adds a new dataset import entry to database using data access object.

        :param parameters: dataset import parameters.
        :param request_user: Django user who initiated the request.
        :type parameters: dict
        :return: dataset ID of the added dataset import entry
        :rtype: int
        """
        connections.close_all()
        dataset_import = self._dao.objects.create(
            source_type=self._get_source_type(parameters.get('format', ''), parameters.get('archive', '')),
            source_name=self._get_source_name(parameters),
            elastic_index=parameters.get('texta_elastic_index', ''), elastic_mapping=parameters.get('texta_elastic_mapping', ''),
            start_time=datetime.now(), end_time=None, user=request_user, status='Processing', finished=False,
            must_sync=parameters.get('keep_synchronized', False)
        )
        dataset_import.save()

        return dataset_import.pk 
开发者ID:texta-tk,项目名称:texta,代码行数:22,代码来源:importer.py

示例5: import_one_resource

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def import_one_resource(line):
    """this single resource import function must be outside of the BusinessDataImporter
    class in order for it to be called with multiprocessing"""

    connections.close_all()
    reader = ArchesFileReader()
    archesresource = JSONDeserializer().deserialize(line)
    reader.import_business_data({"resources": [archesresource]}) 
开发者ID:archesproject,项目名称:arches,代码行数:10,代码来源:importer.py

示例6: on_finish

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def on_finish(self):
        connections.close_all() 
开发者ID:zhu327,项目名称:greentor,代码行数:4,代码来源:handlers.py

示例7: run_from_argv

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def run_from_argv(self, argv):
        """
        Set up any environment changes requested (e.g., Python path
        and Django settings), then run this command. If the
        command raises a ``CommandError``, intercept it and print it sensibly
        to stderr. If the ``--traceback`` option is present or the raised
        ``Exception`` is not ``CommandError``, raise it.
        """
        self._called_from_command_line = True
        parser = self.create_parser(argv[0], argv[1])

        if self.use_argparse:
            options = parser.parse_args(argv[2:])
            cmd_options = vars(options)
            # Move positional args out of options to mimic legacy optparse
            args = cmd_options.pop('args', ())
        else:
            options, args = parser.parse_args(argv[2:])
            cmd_options = vars(options)
        handle_default_options(options)
        try:
            self.execute(*args, **cmd_options)
        except Exception as e:
            if options.traceback or not isinstance(e, CommandError):
                raise

            # SystemCheckError takes care of its own formatting.
            if isinstance(e, SystemCheckError):
                self.stderr.write(str(e), lambda x: x)
            else:
                self.stderr.write('%s: %s' % (e.__class__.__name__, e))
            sys.exit(1)
        finally:
            connections.close_all() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:36,代码来源:base.py

示例8: database_exists

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def database_exists(self) -> bool:
        try:
            connection = connections[DEFAULT_DB_ALIAS]

            with connection.cursor() as cursor:
                cursor.execute(
                    "SELECT 1 from pg_database WHERE datname=%s;", [self.database_name],
                )
                return_value = bool(cursor.fetchone())
            connections.close_all()
            return return_value
        except OperationalError:
            return False 
开发者ID:zulip,项目名称:zulip,代码行数:15,代码来源:test_fixtures.py

示例9: get_migration_status

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def get_migration_status(**options: Any) -> str:
    verbosity = options.get('verbosity', 1)

    for app_config in apps.get_app_configs():
        if module_has_submodule(app_config.module, "management"):
            import_module('.management', app_config.name)

    app_label = options['app_label'] if options.get('app_label') else None
    db = options.get('database', DEFAULT_DB_ALIAS)
    out = StringIO()
    command_args = ['--list']
    if app_label:
        command_args.append(app_label)

    call_command(
        'showmigrations',
        *command_args,
        database=db,
        no_color=options.get('no_color', False),
        settings=options.get('settings', os.environ['DJANGO_SETTINGS_MODULE']),
        stdout=out,
        traceback=options.get('traceback', True),
        verbosity=verbosity,
    )
    connections.close_all()
    out.seek(0)
    output = out.read()
    return re.sub(r'\x1b\[(1|0)m', '', output) 
开发者ID:zulip,项目名称:zulip,代码行数:30,代码来源:test_fixtures.py

示例10: process_message

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def process_message(
        self, peer, mailfrom, rcpttos, data, mail_options=None, rcpt_options=None
    ):
        # get a new db connection in case the old one has timed out:
        connections.close_all()

        to_parts = rcpttos[0].split("@")
        code = to_parts[0]

        try:
            data = data.decode()
        except UnicodeError:
            data = "[binary data]"

        if not RE_UUID.match(code):
            self.stdout.write("Not an UUID: %s" % code)
            return

        try:
            check = Check.objects.get(code=code)
        except Check.DoesNotExist:
            self.stdout.write("Check not found: %s" % code)
            return

        action = "success"
        if check.subject:
            parsed = email.message_from_string(data)
            received_subject = parsed.get("subject", "")
            if check.subject not in received_subject:
                action = "ign"

        ua = "Email from %s" % mailfrom
        check.ping(peer[0], "email", "", ua, data, action)
        self.stdout.write("Processed ping for %s" % code) 
开发者ID:healthchecks,项目名称:healthchecks,代码行数:36,代码来源:smtpd.py

示例11: _pre_setup

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def _pre_setup(self):
        from django.db import connections
        connections.close_all()

        super()._pre_setup() 
开发者ID:dibs-devs,项目名称:chatter,代码行数:7,代码来源:test_chat_behavior.py

示例12: test_all_schemas_in_sequential

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def test_all_schemas_in_sequential(self):
        # If there are no errors, then this test passed
        management.call_command("migrate", all_schemas=True, executor="sequential", verbosity=0)
        connections.close_all() 
开发者ID:lorinkoz,项目名称:django-pgschemas,代码行数:6,代码来源:test_executors.py

示例13: test_all_schemas_in_parallel

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def test_all_schemas_in_parallel(self):
        # If there are no errors, then this test passed
        management.call_command("migrate", all_schemas=True, executor="parallel", verbosity=0)
        connections.close_all() 
开发者ID:lorinkoz,项目名称:django-pgschemas,代码行数:6,代码来源:test_executors.py

示例14: _import_dataset

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def _import_dataset(parameter_dict, n_processes, process_batch_size):
    """Starts the import process from a parallel process.

    :param parameter_dict: dataset importer's parameters.
    :param n_processes: size of the multiprocessing pool.
    :param process_batch_size: the number of documents to process at any given time by a process.
    :type parameter_dict: dict
    :type n_processes: int
    :type process_batch_size: int
    """
    from django import db
    db.connections.close_all()

    # Local files are not extracted from archives due to directory permissions
    # If importing from local hard drive, extract first.
    if parameter_dict['is_local'] is False:
        if 'file_path' not in parameter_dict:
            parameter_dict['file_path'] = download(parameter_dict['url'], parameter_dict['directory'])

        _extract_archives(parameter_dict)

    reader = DocumentReader()
    _set_total_documents(parameter_dict=parameter_dict, reader=reader)
    _run_processing_jobs(parameter_dict=parameter_dict, reader=reader, n_processes=n_processes, process_batch_size=process_batch_size)

    # After import is done, remove files from disk
    tear_down_import_directory(parameter_dict['directory']) 
开发者ID:texta-tk,项目名称:texta,代码行数:29,代码来源:importer.py

示例15: _set_total_documents

# 需要导入模块: from django.db import connections [as 别名]
# 或者: from django.db.connections import close_all [as 别名]
def _set_total_documents(parameter_dict, reader):
    """Updates total documents count in the database entry.

    :param parameter_dict: dataset import's parameters.
    :param reader: dataset importer's document reader.
    """
    connections.close_all()
    dataset_import = DatasetImport.objects.get(pk=parameter_dict['import_id'])
    dataset_import.total_documents = reader.count_total_documents(**parameter_dict)
    dataset_import.save() 
开发者ID:texta-tk,项目名称:texta,代码行数:12,代码来源:importer.py


注:本文中的django.db.connections.close_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。