本文整理汇总了Python中multiprocessing.util.register_after_fork函数的典型用法代码示例。如果您正苦于以下问题:Python register_after_fork函数的具体用法?Python register_after_fork怎么用?Python register_after_fork使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register_after_fork函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: handle
def handle(self, *args, **options):
def _after_fork(connection):
#to avoid the postgres multiprocess problem when forking
connection.close()
connection.transaction_state = []
connection.savepoint_state = 0
connection._dirty = None
connection._thread_ident = thread.get_ident()
from django import db
register_after_fork(db.connection, _after_fork)
from chronograph.models import Job
procs = []
for job in Job.objects.due():
if not job.check_is_running():
# Only run the Job if it isn't already running
proc = JobProcess(job)
proc.start()
procs.append(proc)
logger.info("%d Jobs are due" % len(procs))
# Keep looping until all jobs are done
while procs:
for i in range(len(procs)):
if not procs[i].is_alive():
procs.pop(i)
break
time.sleep(.1)
开发者ID:ISPM,项目名称:ispm-django-chronograph,代码行数:31,代码来源:cron.py
示例2: CreateEngine
def CreateEngine(self, BaseClass):
try:
engine = create_engine(
"postgresql+psycopg2://{0}:{1}@{2}:{3}/{4}".format(
self._db_settings['DATABASE_USER'],
self._db_settings['DATABASE_PASS'],
self._db_settings['DATABASE_IP'],
self._db_settings['DATABASE_PORT'],
self._db_settings['DATABASE_NAME']),
poolclass=QueuePool,
pool_size=5,
max_overflow=10,)
BaseClass.metadata.create_all(engine)
# Fix for forking
register_after_fork(engine, engine.dispose)
return engine
except ValueError as e: # Potentially corrupted DB config.
self.error_handler.FrameworkAbort(
'Database configuration file is potentially corrupted. '
'Please check ' + self.config.FrameworkConfigGet('DATABASE_SETTINGS_FILE') + '\n'
'[DB] ' + str(e))
except KeyError: # Indicates incomplete db config file
self.error_handler.FrameworkAbort(
"Incomplete database configuration settings in "
"" + self.config.FrameworkConfigGet('DATABASE_SETTINGS_FILE'))
except exc.OperationalError as e:
self.error_handler.FrameworkAbort(
"[DB] " + str(e) + "\nRun scripts/db_run.sh to start/setup db")
开发者ID:DePierre,项目名称:owtf,代码行数:30,代码来源:db.py
示例3: create_engine
def create_engine(self, base):
"""Create the SQLAlchemy engine with parameters
:return: None
:rtype: None
"""
try:
engine = create_engine(
"postgresql+psycopg2://%s:%[email protected]%s:%s/%s" % (
self._db_settings['DATABASE_USER'],
self._db_settings['DATABASE_PASS'],
self._db_settings['DATABASE_IP'],
self._db_settings['DATABASE_PORT'],
self._db_settings['DATABASE_NAME']),
poolclass=QueuePool,
pool_size=5,
max_overflow=10)
base.metadata.create_all(engine)
# Fix for forking
register_after_fork(engine, engine.dispose)
return engine
except ValueError as e: # Potentially corrupted DB config.
self.error_handler.abort_framework(
"Database configuration file is potentially corrupted. Please check %s\n[DB] %s" %
(self.config.get_val('DATABASE_SETTINGS_FILE'), str(e)))
except KeyError: # Indicates incomplete db config file
self.error_handler.abort_framework("Incomplete database configuration settings in %s" %
self.config.get_val('DATABASE_SETTINGS_FILE'))
except exc.OperationalError as e:
self.error_handler.abort_framework("[DB] %s\nRun 'make db-run' to start/setup db" % str(e))
开发者ID:saganshul,项目名称:owtf,代码行数:30,代码来源:database.py
示例4: __init__
def __init__(self, kind, value, maxvalue):
# unlink_now is only used on win32 or when we are using fork.
unlink_now = False
for i in range(100):
try:
self._semlock = _SemLock(
kind, value, maxvalue, SemLock._make_name(),
unlink_now)
except FileExistsError: # pragma: no cover
pass
else:
break
else: # pragma: no cover
raise FileExistsError('cannot find name for semaphore')
util.debug('created semlock with handle %s and name "%s"'
% (self._semlock.handle, self._semlock.name))
self._make_methods()
def _after_fork(obj):
obj._semlock._after_fork()
util.register_after_fork(self, _after_fork)
# When the object is garbage collected or the
# process shuts down we unlink the semaphore name
semaphore_tracker.register(self._semlock.name)
util.Finalize(self, SemLock._cleanup, (self._semlock.name,),
exitpriority=0)
开发者ID:ELVIS-Project,项目名称:music21,代码行数:30,代码来源:synchronize.py
示例5: __init__
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._threaded_acquire = False
def _after_fork(obj):
obj._threaded_acquire = False
register_after_fork(self, _after_fork)
开发者ID:dano,项目名称:aioprocessing,代码行数:7,代码来源:managers.py
示例6: get_sqlalchemy
def get_sqlalchemy(app=None, use_native_unicode=True, session_options=None):
"""
Constructs and returns an instance of :class:`.SQLAlchemy`. Any keyword
arguments provided will be passed to the constructor of :class:`.SQLAlchemy`
"""
db = SQLAlchemy(
app=app, use_native_unicode=use_native_unicode,
session_options=session_options)
# sqlite specific configuration for development
if db.engine.name == "sqlite":
@event.listens_for(Engine, "connect")
def set_sqlite_pragma(dbapi_connection, connection_record):
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.execute("PRAGMA synchronous=OFF")
cursor.execute("PRAGMA journal_mode=MEMORY")
cursor.close()
# When the web application is forked any existing connections
# need to be disposed of. This generally only seems to be a problem
# with Postgres, more specifically psycopg2, but doing this globally
# should not have any ill effects. This problem was discovered while
# testing the Agent using uwsgi 2.0.3, nginx 1.4.6, Postgres 9.1, and
# psycopg2 2.5.2. The bug does not present itself 100% of the time
# making it difficult to test reliably. The fix below is based
# on a fix made to Celery which had the exact same problem ours did:
# https://github.com/celery/celery/issues/1564
#
# This implementation however is based on the suggestion made in Celery
# 3.1's release notes:
# https://celery.readthedocs.org/en/latest/whatsnew-3.1.html
register_after_fork(db.engine, db.engine.dispose)
return db
开发者ID:guidow,项目名称:pyfarm-master,代码行数:35,代码来源:application.py
示例7: __init__
def __init__(self, maxsize=0, reducers=None, ctx=None):
if sys.version_info[:2] >= (3, 4):
super().__init__(maxsize=maxsize, ctx=ctx)
else:
if maxsize <= 0:
# Can raise ImportError (see issues #3770 and #23400)
maxsize = SEM_VALUE_MAX
if ctx is None:
ctx = get_context()
self._maxsize = maxsize
self._reader, self._writer = connection.Pipe(duplex=False)
self._rlock = ctx.Lock()
self._opid = os.getpid()
if sys.platform == 'win32':
self._wlock = None
else:
self._wlock = ctx.Lock()
self._sem = ctx.BoundedSemaphore(maxsize)
# For use by concurrent.futures
self._ignore_epipe = False
self._after_fork()
if sys.platform != 'win32':
util.register_after_fork(self, Queue._after_fork)
self._reducers = reducers
开发者ID:MartinThoma,项目名称:scikit-learn,代码行数:29,代码来源:queues.py
示例8: get_engine
def get_engine(dburi, **kwargs):
try:
return _ENGINES[dburi]
except KeyError:
engine = _ENGINES[dburi] = create_engine(dburi, **kwargs)
after_fork.registered = True
register_after_fork(after_fork, after_fork)
return engine
开发者ID:Aliced3645,项目名称:celery,代码行数:8,代码来源:session.py
示例9: __init__
def __init__(self):
self._key = 0
self._cache = {}
self._old_locks = []
self._lock = threading.Lock()
self._listener = None
self._address = None
self._thread = None
register_after_fork(self, ResourceSharer._afterfork)
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:9,代码来源:reduction.py
示例10: __init__
def __init__(self, kind, value, maxvalue):
sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
debug('created semlock with handle %s' % sl.handle)
self._make_methods()
if sys.platform != 'win32':
def _after_fork(obj):
obj._semlock._after_fork()
register_after_fork(self, _after_fork)
开发者ID:1310701102,项目名称:sl4a,代码行数:9,代码来源:synchronize.py
示例11: pool
def pool(self):
if self._pool is None:
self._pool = self.app.broker_connection().Pool(self.connection_max)
try:
from multiprocessing.util import register_after_fork
register_after_fork(self, self._reset_after_fork)
except ImportError:
pass
return self._pool
开发者ID:pcardune,项目名称:celery,代码行数:9,代码来源:amqp.py
示例12: get_pool
def get_pool(self, next_connection_pool=False):
if (self._pool is None) or next_connection_pool:
try:
from multiprocessing.util import register_after_fork
register_after_fork(self, self._after_fork)
except ImportError:
pass
limit = self.conf.BROKER_POOL_LIMIT
self._pool = self.broker_connection(next_connection=next_connection_pool).Pool(limit)
return self._pool
开发者ID:KarimAllah,项目名称:celery,代码行数:10,代码来源:base.py
示例13: bootstrap_pyramid
def bootstrap_pyramid(signal, sender):
import os
from pyramid.paster import bootstrap
sender.app.settings = \
bootstrap(os.environ['BALISTOS_CONFIG'])['registry'].settings
engine = engine_from_config(sender.app.settings, 'sqlalchemy.')
register_after_fork(engine, engine.dispose)
Session.configure(bind=engine)
开发者ID:ferewuz,项目名称:balistos,代码行数:10,代码来源:tasks.py
示例14: pool
def pool(self):
if self._pool is None:
try:
from multiprocessing.util import register_after_fork
register_after_fork(self, self._after_fork)
except ImportError:
pass
self._pool = self.broker_connection().Pool(
limit=self.conf.BROKER_POOL_LIMIT)
return self._pool
开发者ID:sunliwen,项目名称:celery,代码行数:10,代码来源:base.py
示例15: __init__
def __init__(self, kind, value, maxvalue):
sl = self._semlock = js.eval('new Semaphore(1);')
sl.kind=kind
sl.value=0
sl.maxvalue=maxvalue
debug('created semlock with handle %s' % sl.handle)
self._make_methods()
if sys.platform != 'win32':
def _after_fork(obj):
obj._semlock._after_fork()
register_after_fork(self, _after_fork)
开发者ID:perkinslr,项目名称:pypyjs-release,代码行数:12,代码来源:synchronize.py
示例16: __init__
def __init__(self, out_file = None):
logging.Handler.__init__(self)
if out_file is not None:
self._handler = FH(out_file)
else:
self._handler = SH()
self.queue = multiprocessing.Queue(-1)
atexit.register(logging.shutdown)
self._thrd = None
self._is_child = False
# Children will automatically register themselves as chilcren
register_after_fork(self, MPLogHandler.set_is_child)
开发者ID:nEDM-TUM,项目名称:HimbeereCouch,代码行数:15,代码来源:log.py
示例17: flask_app
def flask_app(self):
if has_app_context():
return flask_current_app._get_current_object()
self.flask_app_factory = symbol_by_name(self.flask_app_factory)
app = self.flask_app_factory()
if 'sentry' in app.extensions:
from raven.contrib.celery import register_signal, register_logger_signal
client = app.extensions['sentry'].client
client.tags['process_type'] = 'celery task'
register_signal(client)
register_logger_signal(client)
register_after_fork(app, self._setup_after_fork)
return app
开发者ID:debon,项目名称:abilian-core,代码行数:16,代码来源:celery.py
示例18: connect
def connect(self):
"""
Creates the backend instance for this database and connects it to its
database server.
:sa backend
:return <bool> | success
"""
backend = self.backend()
if backend:
# disconnect after a multiprocess fork or this will error out
register_after_fork(self, self.disconnect)
return backend.open()
return False
开发者ID:SPRIME01,项目名称:orb,代码行数:16,代码来源:database.py
示例19: __init__
def __init__(self, maxsize=0):
if maxsize <= 0:
maxsize = 2147483647L
self._maxsize = maxsize
self._reader, self._writer = Pipe(duplex=False)
self._rlock = Lock()
self._opid = os.getpid()
if sys.platform == 'win32':
self._wlock = None
else:
self._wlock = Lock()
self._sem = BoundedSemaphore(maxsize)
self._after_fork()
if sys.platform != 'win32':
register_after_fork(self, Queue._after_fork)
开发者ID:perkinslr,项目名称:pypyjs-release,代码行数:17,代码来源:queues.py
示例20: flask_app
def flask_app(self):
if has_app_context():
return unwrap(flask_current_app)
self.flask_app_factory = symbol_by_name(self.flask_app_factory)
app = self.flask_app_factory()
if "sentry" in app.extensions:
from raven.contrib.celery import register_signal, register_logger_signal
client = app.extensions["sentry"].client
client.tags["process_type"] = "celery task"
register_signal(client)
register_logger_signal(client)
register_after_fork(app, self._setup_after_fork)
return app
开发者ID:abilian,项目名称:abilian-core,代码行数:17,代码来源:celery.py
注:本文中的multiprocessing.util.register_after_fork函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论