-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmanager.py
More file actions
76 lines (59 loc) · 2.15 KB
/
tmanager.py
File metadata and controls
76 lines (59 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#
# Written by: Carlos Bazaga
#
# Licensed under BSD 2-Clause
#
from multiprocessing.managers import SyncManager
from tpool import Tpool
from tspy import Tspy
class Tmanager(SyncManager):
"""
This class defines a subuclass of SyncManager with some TLib classes preregistered and
an internal "Tspy" object instanced.
The classes preregistered for public use are:
Tmanager as "Tmanager"
Tpool as "Tpool"
Aditionally an "only for internal use" registering is made:
Tspy as "A_Tspy_Inside"
The internal Tspy's methods are reachable from outside via the proxy mechanism
handled by the parent class SyncManager.
"""
def __init__(self, name):
"""
Return a new Tmanager.
Tmanagers process's name will be overwritten with "name".
"""
SyncManager.__init__(self)
self.name = name
def start(self):
"""
Spawn a server process for this manager object and create a Tspy object inside.
The Tspy will be accesible as a proxy object on Tmanager's "tspy" atribute.
"""
SyncManager.start(self)
self.tspy = self.A_Tspy_Inside(self.name)
# Now we add the Tspy proxy to the Tmanager's process and edit his name.
self._process.tspy = self.tspy
self._process.name = self.name
def shutdown(self):
"""
Bridge method to parent class's 'shutdown' method.
This bridge allows Tmanagers inside a Tmanager to be stopped.
Tmanagers inside a Tmanager should be shutted down from innermost to outermost.
"""
SyncManager.shutdown(self)
def join(self):
"""
Bridge method to parent class's 'join' method.
This bridge allows Tmanagers inside a Tmanager' process to be joined.
Tmanagers inside a Tmanager should be joined from innermost to outermost.
"""
SyncManager.join(self)
### Registration of default Tlib classes on Tmanager.
Tmanager.register('A_Tspy_Inside', Tspy)
Tmanager.register('Tmanager', Tmanager)
Tmanager.register('Tpool', Tpool)
def Launch(name):
manager = Tmanager(name)
manager.start()
return manager