客户端意外关闭了TCP连接

时间:2017-06-24 21:29:05

标签: python rabbitmq celery rabbitmq-exchange

我有几项任务作为服务运行。要启动工作人员,请使用:

import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
import numpy as np

instances = np.array([[ 1,  2],
                      [ 3,  4],
                      [ 5,  6]])
pca = PCA(n_components=2).fit(instances)
pca_2d = pca.transform(instances)

fig = plt.figure(figsize=(8,3))
plt.scatter(pca_2d[:,0],pca_2d[:,1])
plt.show()

开始使用python 任务作为我使用的服务:

def SvcDoRun(self):
    logging.info('Starting {name} service ...'.format(name=self._svc_name_))
    os.chdir(INSTDIR) # so that proj worker can be found
    logging.info('cwd: ' + os.getcwd())

    self.ReportServiceStatus(win32service.SERVICE_RUNNING)

    command = '{celery_path} -A {proj_dir} worker -f "{log_path}" -l info --hostname=theService@%h'.format(
        celery_path='celery',
        proj_dir=PROJECTDIR,
        log_path=os.path.join(INSTDIR,'celery.log'))

    logging.info('command: ' + command)

    args = shlex.split(command)
    proc = subprocess.Popen(args)

    logging.info('pid: {pid}'.format(pid=proc.pid))

    self.timeout = 5000

    while True:
        rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
        if rc == win32event.WAIT_OBJECT_0:
            print 'Terminate'
            # stop signal encountered
            PROCESS_TERMINATE = 1
            handle = win32api.OpenProcess(PROCESS_TERMINATE, False, proc.pid)
            win32api.TerminateProcess(handle, -1)
            win32api.CloseHandle(handle)
            break

' celery.py'包含对这些任务的调用,如celery.py:

def SvcDoRun(self):
      import servicemanager
      servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,servicemanager.PYS_SERVICE_STARTED,(self._svc_name_, ''))

  self.timeout = 640000    #640 seconds / 10 minutes (value is in milliseconds)
  # This is how long the service will wait to run / refresh itself (see script below)

  while 1:
     try:
        # Wait for service stop signal, if I timeout, loop again
        rc = win32event.WaitForSingleObject(self.hWaitStop, self.timeout)
        # Check to see if self.hWaitStop happened
        if rc == win32event.WAIT_OBJECT_0:
           # Stop signal encountered
           servicemanager.LogInfoMsg(self._svc_name_ + " - STOPPED!")  #For Event Log
           break
        else:
           #[actual service code between rests]
           try:
              file_path = "C:\framework\celery\celery.py"
              execfile(file_path)             #Execute the script

           except Exception as exc:
              traceback.print_exc(file=sys.stdout)
           #[actual service code between rests]
     except Exception as exc:
        traceback.print_exc(file=sys.stdout)

问题 我致电任务' from __future__ import absolute_import, unicode_literals from celery import Celery app = Celery(include=[ 'framework.task1.tasks', 'framework.task2.tasks', 'framework.task3.tasks', 'framework.task4.tasks' ]) app.config_from_object('config') if __name__ == '__main__': app.start() '但有时候任务永远不会执行然后我再次发送它(或两次)并且它有效......看着我看到的rabbitmq日志文件:

python runTask1.py param1 param2 param3

为什么有时它会起作用,有时却不起作用?

0 个答案:

没有答案