Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多个线程对 self._cli 操作导致 close 找不到 #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions ios_device/servers/dvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import queue
import typing
from collections import defaultdict
from threading import Thread, Event
from threading import Thread, Event, Lock

from ..util import logging, Log
from ..util.dtx_msg import DTXMessage, MessageAux, dtx_message_header, object_to_aux
Expand All @@ -11,6 +11,8 @@

log = Log.getLogger(LOG.Instrument.value)

dvt_lock = Lock()


class DTXEnum(str, enum.Enum):
FINISHED = "finished:"
Expand Down Expand Up @@ -131,9 +133,10 @@ def stop(self):
self._running = False
if self._recv_thread:
self._recv_thread = None
if self._cli:
self._cli.close()
self._cli = None
with dvt_lock:
if self._cli:
self._cli.close()
self._cli = None

def _run_callbacks(self, event_name, data):
"""
Expand Down Expand Up @@ -227,7 +230,8 @@ def _receiver(self):
while self._running:
dtx = self._client.recv_dtx(self._cli)
if '_channelCanceled:' in str(dtx.selector):
self._cli.close()
with dvt_lock:
self._cli.close()
if dtx.conversation_index == 1:
self._reply_queues[dtx.identifier].put(dtx)
elif (2 ** 32 - dtx.channel_code) in self._channel_callbacks:
Expand Down