当前位置: 动力学知识库 > 问答 > 编程问答 >

Python: What are the dangers of passing a specific object's function as an argument

问题描述:

In the main code, I have an instance of a class called "debugPrinterObject".

After instantiating it, I pass one of it's functions as an argument to another class called "bSoupProcessor" which processes text. Any logging information is saved to a text file using the function passed into the constructor of the bSoupProcessor class.

This is done so that the file is held open by the debugPrinterObject, and editable through the function passed as an argument. the text file is only closed at the end of the program.

It is working so far. I am going to implement multi threading, where there will be multiple "bSoupProcessor" classes, and they will all be using the same function of the "debugPrinterObject". Is this possible? are there any problems/risks?

网友答案:

The only dangers are the typical concurrency issues you'd face in this situation. Be sure to either use Lock objects inside your logging method, or use them in bSoupProcessor before calling it.

分享给朋友:
您可能感兴趣的文章:
随机阅读: