我试图让python客户端使用一个全局变量,这样我就可以将它重用到多个函数中。
我在RTC项目中使用这个工具,我有一个功能良好的js客户端,但是这些功能与python不同。服务器和js客户端上的函数是我自己的,没有参数,我希望避免在我正在开发的python客户机上使用它们。
我一直在使用他们的github中的aiortc Cli.py作为我的python应该如何工作的基础。但我不会异步运行它,因为我正在尝试学习和控制事件发生的时间。源代码可以在这里找到,我指的是第71-72行https://github.com/aiortc/aiortc/blob/master/examples/datachannel-cli/cli.py中的代码。
这是我想要正确运行的代码
我只插入了与当前问题
相关的代码
import argparse
import asyncio
import logging
import time
from aiortc import RTCIceCandidate, RTCPeerConnection, RTCSessionDescription
from aiortc.contrib.signaling import add_signaling_arguments, create_signaling
pc = None
channel = None
def createRTCPeer():
print("starting RTC Peer")
pc = RTCPeerConnection()
print("created Peer", pc)
return pc
def pythonCreateDataChannel():
print("creating datachannel")
channel = pc.CreateDataChannel("chat")createRTCPeer函数按预期工作,它创建了RTC对象,但如果在使用之前将其设置为“to”,则pythonCreateDataChannel会报告一个错误。
AttributeError:“NoneType”对象没有属性“CreateDataChannel”
它会报告
NameError:未定义名称“通道”
如果我不把它设置在全局范围内的话,pc也是一样。
发布于 2019-09-27 11:57:01
你试过这个吗?
import argparse
import asyncio
import logging
import time
from aiortc import RTCIceCandidate, RTCPeerConnection, RTCSessionDescription
from aiortc.contrib.signaling import add_signaling_arguments, create_signaling
pc = None
channel = None
def createRTCPeer():
print("starting RTC Peer")
global pc
pc = RTCPeerConnection()
print("created Peer", pc)
def pythonCreateDataChannel():
print("creating datachannel")
global channel
channel = pc.CreateDataChannel("chat")https://stackoverflow.com/questions/58133832
复制相似问题