English 中文(简体)
Spa a read containing
原标题:Spawning a QThread containing a socket connection in python

我目前正在尝试实施一个包含袖珍连接的曲线。 单相连接多次(同时1:)检查收到的新数据。 一旦收到这一数据,它就应当停用一个称为“SignAL”的功能,并向它提供所收到的数据。

我用的是袖珍连接。 当我自己行使职能时,只要有新数据,就等待数据和印刷。 然而,由于我正试图与Qt一道建立一个全球倡议,我不得不把这一点放在自己的一边,以便让人们能够继续运作。

因此,我读完了一套通用读物,可以发挥任何功能,在校内操作。 My MainWindow阶级连接了SignAL的袖珍,即刻板,然后开始。 然而,这造成了我的 app。 以下是相关法典:

接线<>

def remoteConn(self, HOST= my.server , PORT=25562):
  import socket
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((HOST, PORT))
  newLinesRaw =   
  while 1:
    newData = s.recv(1024)
    if newData:
      print  <rawData>
 , newData,  
</newData>
 
      newLinesRaw += newData
    else:
      if newLinesRaw:
        newLines = newLinesRaw.split( 
 )
        print  
New Lines:
 , newLines
        self.emit(QtCore.SIGNAL( newRemoteLines ), newLines)
        newLinesRaw=  
      else:
        time.sleep(.1)
  s.close()

通用读物类别

class GenericThread(QtCore.QThread):
  def __init__(self, function, *args, **kwargs):
    QtCore.QThread.__init__(self)
    self.function = function
    self.args = args
    self.kwargs = kwargs

  def __del__(self):
    self.wait()

  def run(self):
    if self.args and self.kwargs:
      self.function(*self.args,**self.kwargs)
    elif self.args and not self.kwargs:
      self.function(*self.args)
    elif not self.args and self.kwargs:
      self.function(**self.kwargs)
    else:
      self.function()
    return

播下遥远的路面。 请注意,两份印刷声明均已执行。

  print  spawning remote thread 
  self.connect(self, QtCore.SIGNAL( newRemoteLines ), self.routeServerLines)
  thread = GenericThread(self.remoteConn)
  thread.start()
  print  thread started 

我是新来的,可以坐下来,这样,我可能会在某个地方造成非常严重的错误。

最佳回答

The thread might be destroyed if there is no further reference to it.

Try using self.thread instead of just thread.

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...