开发者

Creating thread in python rewrites another structure

开发者 https://www.devze.com 2023-03-05 23:41 出处:网络
in my Python program I use my own C library where I have quite complicated structure (I use Python only to create GUI). After creating another thread which should handle some calculations going on in

in my Python program I use my own C library where I have quite complicated structure (I use Python only to create GUI). After creating another thread which should handle some calculations going on in the C module, one of the char * in the C structure (maybe more, but I didn't find any other yet) contains following string: 'thread开发者_运维百科.lock' object has no attribute '_is_owned' instead of what it shloud contain. I use testing method to print the string. I case I call it before the thread initialization the string is OK, but if I call it afterwards it's changed.

class MyThread (threading.Thread):
    def __init__(self, window):
        library.test_print()
        self.window = window
        threading.Thread.__init__(self)
        library.test_print()

I don't suppose there is bug in Python (or is there?) but i don't see what could I be possibly doing wrong. Do you have any ideas?


I figured it out. The problem was I didn't make defense copy of the string when storing it into char* in my structure and python had no problem overwriting that very memory space with another string although my pointer was still pointing to it. Thanks for your time everyone.

0

精彩评论

暂无评论...
验证码 换一张
取 消