0

我现在的目标是创建 team speak 3 manager 服务(通过渠道切换用户):所以我创建了 TS3 SDK lib 的包装器(用 Cython for Python 包装):https://mega.nz/#!pQdFjIwD! 1vg8DPsFtYR4icVqWXzvpdbAQ47-n-aPz2niRkTU4fY(主模块:http ://pastebin.com/PywhH4bf )在这个包装器中,我在模块中使用了测试连接。要测试这个模块,只需导入它。

我在 python 控制台中收到消息(调用后ts3client_startConnection):(Process finished with exit code -1073741819 (0xC0000005)访问冲突)

此外,正如我所见,TS3 回调是从非主线程调用的。

使用此日志:

2016-08-16 10:14:20.862577|INFO    |              |   |TeamSpeak 3 Client 3.0.3 (2015-03-30 11:30:36) SDK
2016-08-16 10:14:20.863574|INFO    |              |   |SystemInformation: Windows 9 8664 {6} {3} {9600}  (9600) x64 (AMD or Intel) Binary: 32bit
2016-08-16 10:14:20.863574|INFO    |              |   |Using hardware aes
2016-08-16 10:14:20.876587|DEBUG   |Direct Sound  |   |setting timer resolution to 1ms
2016-08-16 10:14:20.892602|ERROR   |SoundBckndIntf|   |Could not load "ts3soundbackend_isSupported" from backend dynamic library
spawn connection handler
mode
Default capture mode: b'Windows Audio Session'

('Default capture device: %s %s\n', b'\xd0\x9c\xd0\xb8\xd0\xba\xd1\x80\xd0\xbe\xd1\x84\xd0\xbe\xd0\xbd (\xd0\xa3\xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xb9\xd1\x81\xd1\x82\xd0\xb2\xd0\xbe \xd1\x81 \xd0\xbf\xd0\xbe\xd0\xb4\xd0\xb4\xd0\xb5\xd1\x80\xd0\xb6\xd0\xba\xd0\xbe\xd0\xb9 High Definition Audio)', b'{0.0.1.00000000}.{c28d826f-9cd5-414b-a018-bbfc0cbc1298}')
2016-08-16 10:14:20.905616|DEBUG   |Windows Audio Session|   |WAS::openDevice-enter
2016-08-16 10:14:20.912622|DEBUG   |Windows Audio Session|   |WAS Buffer size: 896
2016-08-16 10:14:20.912622|DEBUG   |Windows Audio Session|   |WAS::openDevice-leave
2016-08-16 10:14:20.912622|INFO    |PreProSpeex   |1  |Speex version: speex-1.2beta3
2016-08-16 10:14:20.912622|DEBUG   |Windows Audio Session|   |WAS::startDevice-enter
2016-08-16 10:14:20.913622|DEBUG   |Windows Audio Session|   |WAS::startDevice-leave
Default playback mode: b'Windows Audio Session'

('Default playback device: %s %s\n', b'\xd0\x94\xd0\xb8\xd0\xbd\xd0\xb0\xd0\xbc\xd0\xb8\xd0\xba\xd0\xb8 (\xd0\xa3\xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xb9\xd1\x81\xd1\x82\xd0\xb2\xd0\xbe \xd1\x81 \xd0\xbf\xd0\xbe\xd0\xb4\xd0\xb4\xd0\xb5\xd1\x80\xd0\xb6\xd0\xba\xd0\xbe\xd0\xb9 High Definition Audio)', b'{0.0.0.00000000}.{cb324415-bf79-473b-9a59-69a1ca4bfe56}')
2016-08-16 10:14:20.913622|DEBUG   |Windows Audio Session|   |WAS::openDevice-enter
2016-08-16 10:14:20.918627|DEBUG   |Windows Audio Session|   |WAS Buffer size: 896
2016-08-16 10:14:20.918627|DEBUG   |Windows Audio Session|   |WAS::openDevice-leave
2016-08-16 10:14:20.918627|DEBUG   |Windows Audio Session|   |WAS::startDevice-enter
2016-08-16 10:14:20.918627|DEBUG   |Windows Audio Session|   |WAS::startDevice-leave
creating identity
Using identity: b'295V/MObSjZ2wIe+dMWhUoLET/UpS6ENHlhWSVdYYSZ5UnQTU3dneUFQLAF/FDVRBXkaFVFeAH10V1cDQn0Gd3BVYgFgXwV4IgxjOVB2DCwtET9TfgcaA31GE1MBZFxLBXtgDHd9WHFka0NJUUQweGprQnp2cjNrSkxBMXJaazRWeDJMTkRUOUlXcVVyZ0p0WnpDU0lDOVlRPT0='

Client lib initialized and running

Connect status changed: 1 1 0

2016-08-16 10:14:20.926635|DEVELOP |PktHandler    |   |Puzzle solve time: 7
Connect status changed: 1 2 0

Connect status changed: 1 3 0

Connect status changed: 1 4 0

我也得到了不可重复的随机错误:

Fatal Python error: GC object already tracked

Fatal Python error: PyThreadState_Get: no current thread
4

1 回答 1

0

由于缺乏可验证的示例,这有点猜测。

如果从 C 库 (ts3client_*) 创建的线程调用这些处理函数,则在调用 python 函数时尚未正确获取GIL 。

添加with gil喜欢

cdef void onConnectStatusChang‌​eEvent(uint64 serverConnectionHand‌​lerID,
                                     int newStatus, 
                                     unsigned int errorNumber) with gil:

可能会有所帮助。

末尾也没有代码,__main__()主线程至少处于空闲状态可能会更好。

if (error != ERROR_ok):
    print("Error connecting to server: %d\n"% error)

print("Client lib initialized and running\n")

可以在 print 调用之后添加以下行以进行快速测试

import time
while True:
    time.sleep(1.0)
于 2016-08-16T21:09:33.500 回答