def findStats():
thread1 = thread.start_new_thread(func1, (arg_1, arg_2))
thread2 = thread.start_new_thread(func2, (arg_3, arg_4))
def func1(arg_1, arg_2):
"""
Some code which prints some stuff
"""
def func2(arg_3, arg_4):
"""
Some code which prints some other stuff
"""
在這裏,我想要做的就是捕捉FUNC1和FUNC2打印輸出在兩個不同的字符串,以便我可以使用,以顯示他們在兩個不同的標籤我的GUI。重定向線程的輸出到一個字符串在Python
另外,我嘗試使用StringIO(),但由於它們是並行運行的線程,所以輸出順序顯然搞砸了。我正在學習使用子過程的東西,但不知道如何......仍在嘗試。
可以這樣做嗎?如果是這樣,請給我一個方法。在此先感謝:)
使用它變得複雜。不過,這個想法很好。爲了我的需要,我的答案中的代碼很好。 – VoodooChild92 2012-07-12 12:21:04