Coverage for /run/media/veganeco/water/status600.com/pypi/reptilian_climates/modules_series_2/ships/fields/gardens/ships/process/multi_2/__init__.py: 29%
69 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-22 16:05 -0800
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-22 16:05 -0800
3'''
4 calendar:
5 [ ] output recorder
6 [ ] coverage
7 [ ] start in background
8'''
11"""
12 import ships.process.multi as multiproc
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 ],
30 #
31 # True -> wait for "ctrl and c"
32 #
33 wait = False
34 )
36 processes = multiprocs.processes
38 time.sleep (.5)
41 #
42 # stop
43 #
44 multiprocs.stop ()
45"""
47import rich
48import pexpect
50from subprocess import Popen
51import shlex
52import atexit
54import coverage
56def start (
57 coverage_dir = "",
58 processes = [],
59 wait = False
60):
61 processes_list = []
63 cov = coverage.Coverage ()
64 cov.start ()
66 for process in processes:
67 if (type (process) == str):
68 routine = Popen (shlex.split (process_string))
70 #print ('routine:', routine)
72 processes_list.append (routine)
74 elif (type (process) == dict):
75 process_string = process ["string"]
77 cwd = None
78 env = None
80 args = {}
81 if ("Popen" in process):
82 args = process ["Popen"]
84 #
85 # a noop
86 #
87 journal = lambda *args, **kwargs: None
88 if ("journal" in process):
89 journal = process ["journal"]
91 '''
92 report = {
93 "journal": []
94 }
95 '''
105 p = pexpect.spawn (
106 process_string,
107 ** args
108 )
109 def awareness_EOF (p):
110 while not p.eof ():
111 line = p.readline ()
113 try:
114 UTF8_line = line.decode ('UTF8')
115 UTF8_parsed = "yes"
116 except Exception:
117 UTF8_line = ""
118 UTF8_parsed = "no"
120 try:
121 hexadecimal_line = line.hex ()
122 hexadecimal_parsed = "yes"
123 except Exception:
124 hexadecimal_line = ""
125 hexadecimal_parsed = "no"
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 };
139 journal (line_parsed)
141 #report ["journal"].append (line_parsed)
143 #print (line, line_parsed)
145 #rich.print_json (data = line_parsed)
147 awareness_EOF (p)
149 '''
150 this_process_Popen = Popen (
151 shlex.split (process_string),
152 ** args
153 )
154 '''
156 #print ('this_process_Popen:', p)
158 processes_list.append (p)
161 def stop ():
162 print ('stopping')
164 for process in processes_list:
165 process.close ()
167 cov.stop ()
168 cov.save ()
169 cov.html_report (directory = "coverage_report")
171 '''
172 This might only work if this is called:
173 process.wait ()
174 '''
175 atexit.register (stop)
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 ()
185 class returns:
186 def __init__ (this, processes):
187 this.processes = processes
189 def stop (this):
190 print ("stop called")
192 stop ()
194 this_returns = returns (
195 processes = processes_list
196 )
198 print (this_returns)
200 return this_returns