我有两个类OpenInvitation
和Acceptinvitation
我要访问self.socketIOReqAccept
,这是一个从OpenInvitation
到Acceptinvitation
的socketIO对象
OpenInvitation 类
from socketIO_client_nexus import SocketIO, LoggingNamespace
import threading
class OpenInvitation():
def __init__(self):
thread = threading.Thread(target=self.socket)
thread.start()
def socket(self):.
def getSID(args):
NOWsocketID = args
self.socketIDfromOpenforPlay = NOWsocketID
print(NOWsocketID)
self.socketIOReqAccept = SocketIO('http://192.168.219.1', 5200, LoggingNamespace)
self.socketIOReqAccept.on('s_id', getSID)
self.socketIOReqAccept.wait()
我正在尝试从打开的Invitation类中访问self.socketIOReqAccept
变量。
我在另一个线程中尝试过socketIO = self.OpenForPlay.socketIOReqAccept
,但是它正在停止同时运行的GUI。
请帮助我解决这个问题。
答案 0 :(得分:0)
在初始化方法中实例化self.sockerIOReqAccept
:
from socketIO_client_nexus import SocketIO, LoggingNamespace
import threading
class OpenInvitation():
def __init__(self):
self.socketIOReqAccept = SocketIO('http://192.168.219.1', 5200, LoggingNamespace)
thread = threading.Thread(target=self.socket)
thread.start()
def socket(self):.
def getSID(args):
NOWsocketID = args
self.socketIDfromOpenforPlay = NOWsocketID
print(NOWsocketID)
self.socketIOReqAccept.on('s_id', getSID)
self.socketIOReqAccept.wait()
oi = OpenInvitation()
socker = oi.socketIOReqAccept