Skip to content

Commit 6991fcf

Browse files
committed
Add world.supyprocessing
1 parent d43edf7 commit 6991fcf

2 files changed

Lines changed: 38 additions & 20 deletions

File tree

plugins/SedRegex/__init__.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,31 @@
3737
import supybot
3838
import supybot.world as world
3939

40-
__version__ = supybot.version.version
41-
__author__ = supybot.Author("Michael Daniel Telatynski", "t3chguy", "postmaster@webdevguru.co.uk")
42-
__contributors__ = {supybot.authors.jlu:
43-
["options bolding the replacement text", "misc. bug fixes and enhancements"],
44-
supybot.Author('nyuszika7h', 'nyuszika7h', 'nyuszika7h@openmailbox.org'):
45-
["_unpack_sed method within plugin.py"]
46-
}
47-
__maintainer__ = supybot.authors.limnoria_core
40+
if not world.supyprocessing:
41+
__version__ = supybot.version.version
42+
__author__ = supybot.Author("Michael Daniel Telatynski", "t3chguy", "postmaster@webdevguru.co.uk")
43+
__contributors__ = {supybot.authors.jlu:
44+
["options bolding the replacement text", "misc. bug fixes and enhancements"],
45+
supybot.Author('nyuszika7h', 'nyuszika7h', 'nyuszika7h@openmailbox.org'):
46+
["_unpack_sed method within plugin.py"]
47+
}
48+
__maintainer__ = supybot.authors.limnoria_core
4849

49-
__url__ = 'https://github.com/progval/Limnoria/tree/master/plugins/SedRegex'
50+
__url__ = 'https://github.com/progval/Limnoria/tree/master/plugins/SedRegex'
5051

51-
from . import sedregex
52-
from . import config
53-
from . import plugin
54-
from importlib import reload
52+
from . import sedregex
53+
from . import config
54+
from . import plugin
55+
from importlib import reload
5556

56-
reload(sedregex)
57-
reload(config)
58-
reload(plugin)
57+
reload(sedregex)
58+
reload(config)
59+
reload(plugin)
5960

60-
if world.testing:
61-
from . import test
61+
if world.testing:
62+
from . import test
6263

63-
Class = plugin.Class
64-
configure = config.configure
64+
Class = plugin.Class
65+
configure = config.configure
6566

6667
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

src/world.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ def __init__(self, *args, **kwargs):
8989
super(SupyProcess, self).__init__(*args, **kwargs)
9090
log.debug('Spawning process %q.', self.name)
9191

92+
def run(self):
93+
global supyprocessing
94+
supyprocessing = True
95+
return super().run()
96+
97+
# significantly speeds up starting SupyProcess
98+
multiprocessing.set_forkserver_preload([
99+
"multiprocessing",
100+
"supybot", "supybot.callbacks", "supybot.plugin", "supybot.plugins",
101+
"supybot.irclib", "supybot.ircmsgs", "supybot.ircutils",
102+
"supybot.shlex", "supybot.utils"])
103+
92104
commandsProcessed = 0
93105

94106
ircs = [] # A list of all the IRCs.
@@ -231,6 +243,11 @@ def finished():
231243
starting = False
232244
profiling = False
233245
documenting = False
246+
supyprocessing = False
247+
"""Whether the current process is running as the target of SupyProcess.
248+
249+
Plugins can check if this is True to avoid unnecessary imports that slow down
250+
process initialization."""
234251

235252

236253
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

0 commit comments

Comments
 (0)