Use importlib in place of imp
[mudpy.git] / mudpy / daemon.py
1 # Copyright (c) 2004-2016 Jeremy Stanley <fungi@yuggoth.org>. Permission
2 # to use, copy, modify, and distribute this software is granted under
3 # terms provided in the LICENSE file distributed with this software.
4
5 # core objects for the mudpy engine
6 import sys
7
8 import mudpy
9
10 if sys.version_info >= (3, 4):
11     import importlib
12 else:
13     # Python 3.3 lacks importlib.reload()
14     import imp as importlib
15
16
17 def main():
18
19     # start it up
20     mudpy.misc.setup()
21
22     # loop indefinitely while the world is not flagged for termination or
23     # there are still connected users
24     while (not mudpy.misc.universe.terminate_flag or
25            mudpy.misc.universe.userlist):
26
27         # the world was flagged for a reload of all code/data
28         if mudpy.misc.universe.reload_flag:
29             importlib.reload(mudpy)
30             mudpy.misc.reload_data()
31             mudpy.misc.universe.reload_flag = False
32
33         # do what needs to be done on each pulse
34         mudpy.misc.on_pulse()
35
36     # shut it all down
37     mudpy.misc.finish()
38
39
40 if __name__ == '__main__':
41     sys.exit(main())