mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Fix hang on shutdown.
This commit is contained in:
parent
fb28e71f0b
commit
6d5c32ad4b
@ -1277,7 +1277,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||||||
slave = controller.Slave(q, self.server)
|
slave = controller.Slave(q, self.server)
|
||||||
slave.start()
|
slave.start()
|
||||||
try:
|
try:
|
||||||
while not self._shutdown:
|
while not controller.exit:
|
||||||
self.statusbar.redraw()
|
self.statusbar.redraw()
|
||||||
size = self.drawscreen()
|
size = self.drawscreen()
|
||||||
self.tick(q)
|
self.tick(q)
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
import sys
|
import sys
|
||||||
import Queue, threading
|
import Queue, threading
|
||||||
|
|
||||||
|
exit = False
|
||||||
|
|
||||||
#begin nocover
|
#begin nocover
|
||||||
|
|
||||||
class Msg:
|
class Msg:
|
||||||
@ -34,7 +36,12 @@ class Msg:
|
|||||||
self.acked = False
|
self.acked = False
|
||||||
try:
|
try:
|
||||||
masterq.put(self, timeout=3)
|
masterq.put(self, timeout=3)
|
||||||
return self.q.get()
|
while not exit:
|
||||||
|
try:
|
||||||
|
g = self.q.get(timeout=0.5)
|
||||||
|
except Queue.Empty:
|
||||||
|
continue
|
||||||
|
return g
|
||||||
except (Queue.Empty, Queue.Full):
|
except (Queue.Empty, Queue.Full):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -52,7 +59,6 @@ class Slave(threading.Thread):
|
|||||||
class Master:
|
class Master:
|
||||||
def __init__(self, server):
|
def __init__(self, server):
|
||||||
self.server = server
|
self.server = server
|
||||||
self._shutdown = False
|
|
||||||
self.masterq = None
|
self.masterq = None
|
||||||
|
|
||||||
def tick(self, q):
|
def tick(self, q):
|
||||||
@ -73,7 +79,7 @@ class Master:
|
|||||||
self.masterq = q
|
self.masterq = q
|
||||||
slave = Slave(q, self.server)
|
slave = Slave(q, self.server)
|
||||||
slave.start()
|
slave.start()
|
||||||
while not self._shutdown:
|
while not exit:
|
||||||
self.tick(q)
|
self.tick(q)
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
|
|
||||||
@ -86,9 +92,8 @@ class Master:
|
|||||||
msg.ack()
|
msg.ack()
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if not self._shutdown:
|
global exit
|
||||||
self._shutdown = True
|
if not exit:
|
||||||
|
exit = True
|
||||||
if self.server:
|
if self.server:
|
||||||
self.server.shutdown()
|
self.server.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Queue
|
import Queue
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from libmproxy import console, proxy, filt, flow
|
from libmproxy import console, proxy, filt, flow, controller
|
||||||
import tutils
|
import tutils
|
||||||
import libpry
|
import libpry
|
||||||
|
|
||||||
@ -442,7 +442,7 @@ class uFlowMaster(libpry.AutoTree):
|
|||||||
assert fm.do_server_playback(tutils.tflow())
|
assert fm.do_server_playback(tutils.tflow())
|
||||||
q = Queue.Queue()
|
q = Queue.Queue()
|
||||||
fm.tick(q)
|
fm.tick(q)
|
||||||
assert fm._shutdown
|
assert controller.exit
|
||||||
|
|
||||||
def test_stickycookie(self):
|
def test_stickycookie(self):
|
||||||
s = flow.State()
|
s = flow.State()
|
||||||
|
@ -59,6 +59,7 @@ class TestMaster(controller.Master):
|
|||||||
class ProxyThread(threading.Thread):
|
class ProxyThread(threading.Thread):
|
||||||
def __init__(self, port, testq):
|
def __init__(self, port, testq):
|
||||||
self.tmaster = TestMaster(port, testq)
|
self.tmaster = TestMaster(port, testq)
|
||||||
|
controller.exit = False
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user