MCPcopy
hub / github.com/mitmproxy/mitmproxy / run

Method run

mitmproxy/master.py:54–94  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

52 mitmproxy_ctx.options = self.options
53
54 async def run(self) -> None:
55 with (
56 asyncio_utils.install_exception_handler(self._asyncio_exception_handler),
57 asyncio_utils.set_eager_task_factory(),
58 ):
59 self.should_exit.clear()
60
61 # Can we exit before even bringing up servers?
62 if ec := self.addons.get("errorcheck"):
63 await ec.shutdown_if_errored()
64 if ps := self.addons.get("proxyserver"):
65 # This may block for some proxy modes, so we also monitor should_exit.
66 await asyncio.wait(
67 [
68 asyncio_utils.create_task(
69 ps.setup_servers(), name="setup_servers", keep_ref=False
70 ),
71 asyncio_utils.create_task(
72 self.should_exit.wait(), name="should_exit", keep_ref=False
73 ),
74 ],
75 return_when=asyncio.FIRST_COMPLETED,
76 )
77 if self.should_exit.is_set():
78 return
79 # Did bringing up servers fail?
80 if ec := self.addons.get("errorcheck"):
81 await ec.shutdown_if_errored()
82
83 try:
84 await self.running()
85 # Any errors in the final part of startup?
86 if ec := self.addons.get("errorcheck"):
87 await ec.shutdown_if_errored()
88 ec.finish()
89
90 await self.should_exit.wait()
91 finally:
92 # if running() was called, we also always want to call done().
93 # .wait might be cancelled (e.g. by sys.exit), so this needs to be in a finally block.
94 await self.done()
95
96 def shutdown(self):
97 """

Callers 14

test_exception_handlerFunction · 0.95
installbuilder_installerFunction · 0.45
release.pyFile · 0.45
get_dev_versionFunction · 0.45
build.pyFile · 0.45
elasticlunr.min.jsFile · 0.45
options.pyFile · 0.45
run_externalMethod · 0.45
tflow_js.pyFile · 0.45
options_js.pyFile · 0.45
state_js.pyFile · 0.45

Calls 8

runningMethod · 0.95
doneMethod · 0.95
shutdown_if_erroredMethod · 0.80
waitMethod · 0.80
setup_serversMethod · 0.80
clearMethod · 0.45
getMethod · 0.45
finishMethod · 0.45

Tested by 1

test_exception_handlerFunction · 0.76