Coverage for /run/media/veganeco/water/status600.com/pypi/reptilian_climates/modules_series_2/ships/fields/gardens/ships/process/multi_2/__init__.py: 29%

1

2

3'''

4 calendar:

5 [ ] output recorder

6 [ ] coverage

7 [ ] start in background

8'''

9

10

11"""

12 import ships.process.multi as multiproc

13

14 multiprocs = multiproc.start (

15 processes = [

16 {

17 "string": 'python3 -m http.server 9000',

18 "Popen": {

19 "cwd": None

20 }

21 },

22 {

23 "string": 'python3 -m http.server 9001',

24 "Popen": {

25 "cwd": None

26 }

27 }

28 ],

29

30 #

31 # True -> wait for "ctrl and c"

32 #

33 wait = False

34 )

35

36 processes = multiprocs.processes

37

38 time.sleep (.5)

39

40

41 #

42 # stop

43 #

44 multiprocs.stop ()

45"""

46

47 import rich

48 import pexpect

49

50 from subprocess import Popen

51 import shlex

52 import atexit

53

54 import coverage

55

56 def start (

57 coverage_dir = "",

58 processes = [],

59 wait = False

60):

61 processes_list = []

62

63 cov = coverage.Coverage ()

64 cov.start ()

65

66 for process in processes:

67 if (type (process) == str):

68 routine = Popen (shlex.split (process_string))

69

70 #print ('routine:', routine)

71

72 processes_list.append (routine)

73

74 elif (type (process) == dict):

75 process_string = process ["string"]

76

77 cwd = None

78 env = None

79

80 args = {}

81 if ("Popen" in process):

82 args = process ["Popen"]

83

84 #

85 # a noop

86 #

87 journal = lambda *args, **kwargs: None

88 if ("journal" in process):

89 journal = process ["journal"]

90

91 '''

92 report = {

93 "journal": []

94 }

95 '''

96

97

98

99

100

101

102

103

104

105 p = pexpect.spawn (

106 process_string,

107 ** args

108 )

109 def awareness_EOF (p):

110 while not p.eof ():

111 line = p.readline ()

112

113 try:

114 UTF8_line = line.decode ('UTF8')

115 UTF8_parsed = "yes"

116 except Exception:

117 UTF8_line = ""

118 UTF8_parsed = "no"

119

120 try:

121 hexadecimal_line = line.hex ()

122 hexadecimal_parsed = "yes"

123 except Exception:

124 hexadecimal_line = ""

125 hexadecimal_parsed = "no"

126

127

128 line_parsed = {

129 "UTF8": {

130 "parsed": UTF8_parsed,

131 "line": UTF8_line

132 },

133 "hexadecimal": {

134 "parsed": hexadecimal_parsed,

135 "line": hexadecimal_line

136 }

137 };

138

139 journal (line_parsed)

140

141 #report ["journal"].append (line_parsed)

142

143 #print (line, line_parsed)

144

145 #rich.print_json (data = line_parsed)

146

147 awareness_EOF (p)

148

149 '''

150 this_process_Popen = Popen (

151 shlex.split (process_string),

152 ** args

153 )

154 '''

155

156 #print ('this_process_Popen:', p)

157

158 processes_list.append (p)

159

160

161 def stop ():

162 print ('stopping')

163

164 for process in processes_list:

165 process.close ()

166

167 cov.stop ()

168 cov.save ()

169 cov.html_report (directory = "coverage_report")

170

171 '''

172 This might only work if this is called:

173 process.wait ()

174 '''

175 atexit.register (stop)

176

177 if (wait):

178 for process in processes_list:

179 #

180 # https://docs.python.org/3/library/subprocess.html#subprocess.Popen.wait

181 #

182 process.wait ()

183

184

185 class returns:

186 def __init__ (this, processes):

187 this.processes = processes

188

189 def stop (this):

190 print ("stop called")

191

192 stop ()

193

194 this_returns = returns (

195 processes = processes_list

196 )

197

198 print (this_returns)

199

200 return this_returns

201

202

203

204

205

206