我在 installTapOnBus() 方法中不能做什么?
如果您参考讲座 WWDC 2016 Delivering an Exceptional Audio Experience @ :31 分钟,它提到在实时音频中我不需要创建线程或分配任何内存。
这篇文章也提到了这一点。
这里的游戏名称是将任何可以移动的东西从渲染块移到初始化函数中。这包括分配内存块和调用系统函数之类的事情。
这是我的示例代码:
inputNode?.installTap(onBus: bus,
bufferSize: myTapOnBusBufferSize,
format: theAudioFormat) {
(buffer: AVAudioPCMBuffer!,
time: AVAudioTime!) -> Void in
theShowInfo.audioFormat = theAudioFormat
self.onNewBuffer(buffer)
}
Run Code Online (Sandbox Code Playgroud)
这是否意味着在我的 onNewBuffer() 函数内部
我无法输入以下内容
var myStringArray = ["",""]
Run Code Online (Sandbox Code Playgroud)
或这个 ..
DispatchQueue.main.async(qos: .userInteractive) {
}
Run Code Online (Sandbox Code Playgroud)
或这个?
NotificationCenter.default.post(name: Notification.Name(rawValue: MyNotificationIdentifier), object: nil)
Run Code Online (Sandbox Code Playgroud)
这是否意味着如果我在线程中执行这些调用并分配内存,我的应用程序将会崩溃?
这是否意味着如果我执行 fft 算法,我需要在 onNewBuffer 函数的线程中编写 fft 的所有代码?
我正在尝试打印到一个看起来像这样的文件:
'A'
'1'
'B'
'2'
'C'
'3'
Run Code Online (Sandbox Code Playgroud)
但是,鉴于下面的代码,结果是:
['A']
['B']
['C']
Run Code Online (Sandbox Code Playgroud)
这可能是一个"垒球"问题,但我在这里做错了什么?
l1 = ['1']
l2 = ['A']
l3 = ['2']
l4 = ['B']
l5 = ['3']
l6 = ['C']
listoflists = [l1,l2,l3,l4,l5,l6]
itr = iter(listoflists)
f = open ('order.txt','w')
while True:
try:
itr.next()
s = str(itr.next())
f.write(str('\n'))
f.write(s)
except StopIteration:
break
f.close()
Run Code Online (Sandbox Code Playgroud) 我整理的这个简单的Python方法只是检查Tomcat是否在我们的一台服务器上运行.
import urllib2
import re
import sys
def tomcat_check():
tomcat_status = urllib2.urlopen('http://10.1.1.20:7880')
results = tomcat_status.read()
pattern = re.compile('<body>Tomcat is running...</body>',re.M|re.DOTALL)
q = pattern.search(results)
if q == []:
notify_us()
else:
print ("Tomcat appears to be running")
sys.exit()
Run Code Online (Sandbox Code Playgroud)
如果找不到此行:
<body>Tomcat is running...</body>
Run Code Online (Sandbox Code Playgroud)
它叫:
notify_us()
Run Code Online (Sandbox Code Playgroud)
哪个使用SMTP向我自己发送电子邮件,另一个管理员Tomcat不再在服务器上运行...
我之前没有在Python中使用过re模块...所以我假设有一个更好的方法来做到这一点......我也对美丽的汤开放了一个更优雅的解决方案......但是没有使用它..
试着尽量保持这个......
鉴于这种 :
import os
import subprocess
def check_server():
cl = subprocess.Popen(["nmap","10.7.1.71"], stdout=subprocess.PIPE)
result = cl.communicate()
print result
check_server()
Run Code Online (Sandbox Code Playgroud)
check_server()返回此元组:
('\nStarting Nmap 4.53 ( http://insecure.org ) at 2010-04-07 07:26 EDT\nInteresting ports on 10.7.1.71:\nNot shown: 1711 closed ports\nPORT STATE SERVICE\n21/tcp open ftp\n22/tcp open ssh\n80/tcp open http\n\nNmap done: 1 IP address (1 host up) scanned in 0.293 seconds\n', None)
Run Code Online (Sandbox Code Playgroud)
将方法中的第二行更改为
result, err = cl.communicate()
Run Code Online (Sandbox Code Playgroud)
结果check_server()返回:
Starting Nmap 4.53 ( http://insecure.org ) at 2010-04-07 07:27 EDT
Interesting ports on 10.7.1.71:
Not shown: 1711 closed …Run Code Online (Sandbox Code Playgroud)