-2

我需要一个 python 项目的帮助:

例子:

class MyFrame(wx.Frame):
    def __init__(self, parent, title):    
        super(MyFrame, self).__init__(parent, title=title, size=(330, 300))
        self.InitUI()
        self.Centre()
        self.Show()

    def InitUI(self):
        """
        Subprocess
        """
        subprocess.execMethodFromClass( self , 'Connection' , args1 , args2 , ... )

    def Connection( self ):
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connection.connect(( '192.0.1.135' , 3345 ))
        while True:
            data = self.connection.recv(1024)
            if not data:
                break
            else:
                print data

节目:

subprocess.execMethodFromClass( self , 'Connection' , args1 , args2 , ... )

谢谢!

4

3 回答 3

2
于 2013-05-03T18:15:19.637 回答
1

http://docs.python.org/dev/library/multiprocessing.html

from multiprocessing import Process

def f(name):
    print('hello', name)

if __name__ == '__main__':
    p = Process(target=f, args=('bob',))
    p.start()
    p.join()
于 2013-05-03T17:46:00.603 回答
1

你不能。您使用 subprocess 调用另一个应用程序或脚本以在单独的进程中运行。

subprocess.Popen(cmds)

如果您需要运行一些长时间运行的进程,请查看线程或多处理模块。以下是一些链接:

于 2013-05-03T18:13:05.983 回答