"AttributeError: 'module' object has no attribute 'argv'" with windows service

Issue #97 new
Anonymous created an issue

I have a small Flask app which connects the local host with a proxy host and uses multiprocessing to do so. This is the service.py

import cx_Logging
import cx_Threads
import sys

import win32serviceutil
import win32service
import win32event
import servicemanager
import socket

from multiprocessing import freeze_support

from webapp import webApp

class Handler(object):
    # no parameters are permitted; all configuration should be placed in the
    # configuration file and handled in the Initialize() method
    def __init__(self):
        cx_Logging.Info("creating handler instance")
        self.stopEvent = cx_Threads.Event()

    # called when the service is starting
    def Initialize(self, configFileName):
        cx_Logging.Info("initializing: config file name is %r", configFileName)

    # called when the service is starting immediately after Initialize()
    # use this to perform the work of the service; don't forget to set or check
    # for the stop event or the service GUI will not respond to requests to
    # stop the service
    def Run(self):
        cx_Logging.Info("running service....")

    # called when the service is being stopped by the service manager GUI
    def Stop(self):
        cx_Logging.Info("stopping service...")

    def main(self):

And this is the error I get whenever I try to start the service:

[03284] 2014/07/22 17:27:17.293 starting logging at level ERROR
[03284] 2014/07/22 17:27:17.745 Python exception encountered:
[03284] 2014/07/22 17:27:17.745     Internal Message: exception running service
[03284] 2014/07/22 17:27:17.745     Type => <type 'exceptions.AttributeError'>
[03284] 2014/07/22 17:27:17.745     Value => 'module' object has no attribute 'argv'
[03284] 2014/07/22 17:27:17.745     Traceback (most recent call last):
[03284] 2014/07/22 17:27:17.745       File "ServiceHandler.py", line 32, in Run
[03284] 2014/07/22 17:27:17.745       File "ServiceHandler.py", line 41, in main
[03284] 2014/07/22 17:27:17.745       File "C:\Python27\lib\multiprocessing\__init__.py", line 145, in freeze_support
[03284] 2014/07/22 17:27:17.745       File "C:\Python27\lib\multiprocessing\forking.py", line 336, in freeze_support
    if is_forking(sys.argv):
[03284] 2014/07/22 17:27:17.745     AttributeError: 'module' object has no attribute 'argv'
[01556] 2014/07/22 17:27:17.745 ending logging

I posted this in the cx_Freeze mailing list and Thomas Kluyver told me to report it because it is most likely a bug, and if anyone else encounters this error, you have to add this:

if not hasattr(sys, 'argv'):
    sys.argv  = ['']

before the frozen_support() function.

My specs: Windows 7 Ultimate 32bits Python 2.7.8 Flask 0.9 cx_Freeze 4.3.3

Here's the mail: http://sourceforge.net/p/cx-freeze/mailman/message/32637445/

Comments (1)

  1. Log in to comment