python中创建线程重写另一个结构体
在我的 Python 程序中,我使用自己的 C 库,其中结构相当复杂(我仅使用 Python 来创建 GUI)。创建另一个应该处理 C 模块中进行的一些计算的线程后,C 结构中的 char * 之一(可能更多,但我还没有找到任何其他)包含以下字符串: 'thread.lock' 对象有没有属性“_is_owned”而不是它应包含的内容。我使用测试方法来打印字符串。我的情况是在线程初始化之前调用它,字符串是可以的,但是如果我在之后调用它,它就会改变。
class MyThread (threading.Thread):
def __init__(self, window):
library.test_print()
self.window = window
threading.Thread.__init__(self)
library.test_print()
我不认为 Python 中有错误(或者确实存在?),但我不知道我可能做错了什么。你有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。问题是,当我将字符串存储到我的结构中的 char* 中时,我没有制作该字符串的防御副本,并且 python 没有问题用另一个字符串覆盖该内存空间,尽管我的指针仍然指向它。
感谢大家抽出时间。
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.