Search code examples
pythonsdkcythonaccess-violationteamspeak

Process finished with exit code -1073741819 (0xC0000005) (Cython, TeamSpeak3)


My aim for now is creating team speak 3 manager service (that switches the users by channels an others): So I created wrapper of TS3 SDK lib (wrapped with Cython for Python): https://mega.nz/#!pQdFjIwD!1vg8DPsFtYR4icVqWXzvpdbAQ47-n-aPz2niRkTU4fY (main module: http://pastebin.com/PywhH4bf ) In this wrapper I used test connection in module. To test this module just import this.

And I got message in python console (after call the ts3client_startConnection): Process finished with exit code -1073741819 (0xC0000005) (access violation)

Also as I see the TS3 callbacks are called from non-main thread.

With this log:

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

Also I got not repeatable random errors:

Fatal Python error: GC object already tracked

and

Fatal Python error: PyThreadState_Get: no current thread

Solution

  • Due to lack of a verifiable example, this is a little bit of guessing.

    If those handler functions are called from a thread that is created by the C library (ts3client_*), the GIL has not been properly acquired by the time python functions are called.

    Adding with gil like

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

    may help.

    There is also no code at the end of __main__(), it might be better that the main thread is at least idling.

    if (error != ERROR_ok):
        print("Error connecting to server: %d\n"% error)
    
    print("Client lib initialized and running\n")
    

    The following lines could be added after the print call for a quick test

    import time
    while True:
        time.sleep(1.0)