Just use an initialized array.
This commit is contained in:
parent
2a5e79f3ca
commit
94a9cb44a6
@ -153,10 +153,7 @@ def walker_handle_handler(pdata, _ctype, _filename, payload):
|
||||
call_begin(mod, pdata['data'], frequency)
|
||||
# Only register and increment after the above have worked, so we don't
|
||||
# register if it fails starting.
|
||||
handlers.register(mod)
|
||||
# Ensure that it gets finalized by marking said module as having been
|
||||
# initialized correctly.
|
||||
handlers.markings[mod].append('initialized')
|
||||
handlers.register(mod, initialized=True)
|
||||
pdata['handlercount'] = curcount + 1
|
||||
except:
|
||||
util.logexc(LOG, "Failed at registering python file: %s (part "
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
from time import time
|
||||
|
||||
import collections
|
||||
import contextlib
|
||||
import io
|
||||
import os
|
||||
@ -282,7 +281,7 @@ class ContentHandlers(object):
|
||||
|
||||
def __init__(self):
|
||||
self.registered = {}
|
||||
self.markings = collections.defaultdict(list)
|
||||
self.initialized = []
|
||||
|
||||
def __contains__(self, item):
|
||||
return self.is_registered(item)
|
||||
@ -293,11 +292,13 @@ class ContentHandlers(object):
|
||||
def is_registered(self, content_type):
|
||||
return content_type in self.registered
|
||||
|
||||
def register(self, mod):
|
||||
def register(self, mod, initialized=False):
|
||||
types = set()
|
||||
for t in mod.list_types():
|
||||
self.registered[t] = mod
|
||||
types.add(t)
|
||||
if initialized and mod not in self.initialized:
|
||||
self.initialized.append(mod)
|
||||
return types
|
||||
|
||||
def _get_handler(self, content_type):
|
||||
|
@ -386,12 +386,12 @@ class Init(object):
|
||||
def init_handlers():
|
||||
# Init the handlers first
|
||||
for (_ctype, mod) in c_handlers.iteritems():
|
||||
if 'initialized' in c_handlers.markings[mod]:
|
||||
if mod in c_handlers.initialized:
|
||||
# Avoid initing the same module twice (if said module
|
||||
# is registered to more than one content-type).
|
||||
continue
|
||||
handlers.call_begin(mod, data, frequency)
|
||||
c_handlers.markings[mod].append('initialized')
|
||||
c_handlers.initialized.append(mod)
|
||||
|
||||
def walk_handlers():
|
||||
# Walk the user data
|
||||
@ -413,16 +413,11 @@ class Init(object):
|
||||
def finalize_handlers():
|
||||
# Give callbacks opportunity to finalize
|
||||
for (_ctype, mod) in c_handlers.iteritems():
|
||||
mod_markings = c_handlers.markings[mod]
|
||||
if 'initialized' not in mod_markings:
|
||||
if mod not in c_handlers.initialized:
|
||||
# Said module was never inited in the first place, so lets
|
||||
# not attempt to finalize those that never got called.
|
||||
continue
|
||||
if 'finalized' in mod_markings:
|
||||
# Avoid finalizing the same module twice (if said module
|
||||
# is registered to more than one content-type).
|
||||
continue
|
||||
c_handlers.markings[mod].append('finalized')
|
||||
c_handlers.initialized.remove(mod)
|
||||
try:
|
||||
handlers.call_end(mod, data, frequency)
|
||||
except:
|
||||
|
Loading…
x
Reference in New Issue
Block a user