Python 3 script as windows service









up vote
0
down vote

favorite












I have a problem running my script as a service.



I don't understand what to do with paths.



What I have:



 main.py (main code) service.py (template to install and run main.py
/ |
subdir/ subdir/ config.ini
script1.py script2.py


What in main.py:
1. I read config.ini and get variables with paths, i.e.:



[XLS]
dir = D:\ExcelToSQL
workbook1 = workbook1.xls
workbook2 = workbook2.xls
workbook3 = workbook3.xls

[SQL]
user = root
password = password
host = localhost
database = database
port = 3306
ssl_ca =
ssl_verify_cert =
ssl_key =
ssl_cert =
encoding =


  1. script1 for changing values in XLS workbooks just functions with args and params
    script2 for importing in MySQL DB, again just functions.
    All variables come from config.ini

Main problem when I debug my service. It can't read config.ini:



Error 0xC0000003 - The instance's SvcRun() method failed

Traceback (most recent call last):
File "C:Pythonlibsite-packageswin32libwin32serviceutil.py", line 839, in SvcRun
self.SvcDoRun()
File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLservice.py", line 31, in SvcDoRun
self.main()
File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLservice.py", line 37, in main
app()
File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLpyxlsql.py", line 14, in app
path = config.get ("XLS", "dir")
File "C:Pythonlibconfigparser.py", line 780, in get
d = self._unify_values(section, vars)
File "C:Pythonlibconfigparser.py", line 1146, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'XLS'

(null): (null)


I know where is an issue:
in main.py:
print(sys.argv[0])
output
C:Pythonlibsite-packageswin32PythonService.exe



Is it possible to run the service as I want? Because now it is looking for ini file in C:Pythonlibsite-packageswin32PythonService.exe.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I have a problem running my script as a service.



    I don't understand what to do with paths.



    What I have:



     main.py (main code) service.py (template to install and run main.py
    / |
    subdir/ subdir/ config.ini
    script1.py script2.py


    What in main.py:
    1. I read config.ini and get variables with paths, i.e.:



    [XLS]
    dir = D:\ExcelToSQL
    workbook1 = workbook1.xls
    workbook2 = workbook2.xls
    workbook3 = workbook3.xls

    [SQL]
    user = root
    password = password
    host = localhost
    database = database
    port = 3306
    ssl_ca =
    ssl_verify_cert =
    ssl_key =
    ssl_cert =
    encoding =


    1. script1 for changing values in XLS workbooks just functions with args and params
      script2 for importing in MySQL DB, again just functions.
      All variables come from config.ini

    Main problem when I debug my service. It can't read config.ini:



    Error 0xC0000003 - The instance's SvcRun() method failed

    Traceback (most recent call last):
    File "C:Pythonlibsite-packageswin32libwin32serviceutil.py", line 839, in SvcRun
    self.SvcDoRun()
    File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLservice.py", line 31, in SvcDoRun
    self.main()
    File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLservice.py", line 37, in main
    app()
    File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLpyxlsql.py", line 14, in app
    path = config.get ("XLS", "dir")
    File "C:Pythonlibconfigparser.py", line 780, in get
    d = self._unify_values(section, vars)
    File "C:Pythonlibconfigparser.py", line 1146, in _unify_values
    raise NoSectionError(section) from None
    configparser.NoSectionError: No section: 'XLS'

    (null): (null)


    I know where is an issue:
    in main.py:
    print(sys.argv[0])
    output
    C:Pythonlibsite-packageswin32PythonService.exe



    Is it possible to run the service as I want? Because now it is looking for ini file in C:Pythonlibsite-packageswin32PythonService.exe.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a problem running my script as a service.



      I don't understand what to do with paths.



      What I have:



       main.py (main code) service.py (template to install and run main.py
      / |
      subdir/ subdir/ config.ini
      script1.py script2.py


      What in main.py:
      1. I read config.ini and get variables with paths, i.e.:



      [XLS]
      dir = D:\ExcelToSQL
      workbook1 = workbook1.xls
      workbook2 = workbook2.xls
      workbook3 = workbook3.xls

      [SQL]
      user = root
      password = password
      host = localhost
      database = database
      port = 3306
      ssl_ca =
      ssl_verify_cert =
      ssl_key =
      ssl_cert =
      encoding =


      1. script1 for changing values in XLS workbooks just functions with args and params
        script2 for importing in MySQL DB, again just functions.
        All variables come from config.ini

      Main problem when I debug my service. It can't read config.ini:



      Error 0xC0000003 - The instance's SvcRun() method failed

      Traceback (most recent call last):
      File "C:Pythonlibsite-packageswin32libwin32serviceutil.py", line 839, in SvcRun
      self.SvcDoRun()
      File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLservice.py", line 31, in SvcDoRun
      self.main()
      File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLservice.py", line 37, in main
      app()
      File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLpyxlsql.py", line 14, in app
      path = config.get ("XLS", "dir")
      File "C:Pythonlibconfigparser.py", line 780, in get
      d = self._unify_values(section, vars)
      File "C:Pythonlibconfigparser.py", line 1146, in _unify_values
      raise NoSectionError(section) from None
      configparser.NoSectionError: No section: 'XLS'

      (null): (null)


      I know where is an issue:
      in main.py:
      print(sys.argv[0])
      output
      C:Pythonlibsite-packageswin32PythonService.exe



      Is it possible to run the service as I want? Because now it is looking for ini file in C:Pythonlibsite-packageswin32PythonService.exe.










      share|improve this question















      I have a problem running my script as a service.



      I don't understand what to do with paths.



      What I have:



       main.py (main code) service.py (template to install and run main.py
      / |
      subdir/ subdir/ config.ini
      script1.py script2.py


      What in main.py:
      1. I read config.ini and get variables with paths, i.e.:



      [XLS]
      dir = D:\ExcelToSQL
      workbook1 = workbook1.xls
      workbook2 = workbook2.xls
      workbook3 = workbook3.xls

      [SQL]
      user = root
      password = password
      host = localhost
      database = database
      port = 3306
      ssl_ca =
      ssl_verify_cert =
      ssl_key =
      ssl_cert =
      encoding =


      1. script1 for changing values in XLS workbooks just functions with args and params
        script2 for importing in MySQL DB, again just functions.
        All variables come from config.ini

      Main problem when I debug my service. It can't read config.ini:



      Error 0xC0000003 - The instance's SvcRun() method failed

      Traceback (most recent call last):
      File "C:Pythonlibsite-packageswin32libwin32serviceutil.py", line 839, in SvcRun
      self.SvcDoRun()
      File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLservice.py", line 31, in SvcDoRun
      self.main()
      File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLservice.py", line 37, in main
      app()
      File "D:rs_alIdeaProjectsExcelToSQLPyXLSQLpyxlsql.py", line 14, in app
      path = config.get ("XLS", "dir")
      File "C:Pythonlibconfigparser.py", line 780, in get
      d = self._unify_values(section, vars)
      File "C:Pythonlibconfigparser.py", line 1146, in _unify_values
      raise NoSectionError(section) from None
      configparser.NoSectionError: No section: 'XLS'

      (null): (null)


      I know where is an issue:
      in main.py:
      print(sys.argv[0])
      output
      C:Pythonlibsite-packageswin32PythonService.exe



      Is it possible to run the service as I want? Because now it is looking for ini file in C:Pythonlibsite-packageswin32PythonService.exe.







      python service






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 21 hours ago









      Vineeth Sai

      2,04131020




      2,04131020










      asked 21 hours ago









      Rostislav Aleev

      94




      94



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222233%2fpython-3-script-as-windows-service%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222233%2fpython-3-script-as-windows-service%23new-answer', 'question_page');

          );

          Post as a guest














































































          這個網誌中的熱門文章

          How to combine Bézier curves to a surface?

          Mutual Information Always Non-negative

          Why am i infinitely getting the same tweet with the Twitter Search API?