[issue26434] multiprocessing cannot spawn grandchild from a Windows service

2017-05-18 Thread Davin Potts

Davin Potts added the comment:

Patch committed in 2.7 branch.

Thanks for your help, Marc.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26434] multiprocessing cannot spawn grandchild from a Windows service

2017-05-18 Thread Davin Potts

Davin Potts added the comment:


New changeset c47c315812b1fa9acb16510a7aa3b37d113def48 by Davin Potts (Marc 
Schlaich) in branch '2.7':
bpo-26434: Fix multiprocessing grandchilds in a Windows service (GH-1167)
https://github.com/python/cpython/commit/c47c315812b1fa9acb16510a7aa3b37d113def48


--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26434>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26434] multiprocessing cannot spawn grandchild from a Windows service

2017-05-04 Thread Marc Schlaich

Marc Schlaich added the comment:

I opened a PR on GitHub, please review.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26434] multiprocessing cannot spawn grandchild from a Windows service

2017-04-18 Thread Roundup Robot

Changes by Roundup Robot :


--
pull_requests: +1297

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



ANN: psutil 4.2.0 with Windows service support is out

2016-05-15 Thread Giampaolo Rodola'
Full blog post:
http://grodola.blogspot.com/2016/05/psutil-420-windows-services-and-python.html

-- 
Giampaolo - http://grodola.blogspot.com
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


ANN: psutil 4.2.0 with Windows service support is out

2016-05-15 Thread Giampaolo Rodola'
Full blog post:
http://grodola.blogspot.com/2016/05/psutil-420-windows-services-and-python.html

-- 
Giampaolo - http://grodola.blogspot.com
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: psutil 4.2.0 with Windows service support is out

2016-05-15 Thread Giampaolo Rodola'
Full blog post:
http://grodola.blogspot.com/2016/05/psutil-420-windows-services-and-python.html

-- 
Giampaolo - http://grodola.blogspot.com
-- 
https://mail.python.org/mailman/listinfo/python-list


smtplib not working when python run under windows service via Local System account

2016-05-05 Thread loial
I have a python 2.7.10 script which is being run under a windows service on 
windows 2012 server .
The python script uses smtplib to send an email.

It works fine when the windows service is run as a local user, but not when the 
windows service is configured to run as Local System account. I get no 
exception from smtplib, but the email fails to arrive.

Any ideas?

 
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26434] multiprocessing cannot spawn grandchild from a Windows service

2016-03-03 Thread Marc Schlaich

Marc Schlaich added the comment:

Wrong bug...

--
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26434] multiprocessing cannot spawn grandchild from a Windows service

2016-03-03 Thread Marc Schlaich

Marc Schlaich added the comment:

We have some business privilege management solution running which might have 
corrupted the installation. As no one else is reporting this issue, this is my 
best guest for this phenomena and I'm going to close this issue.

--
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26434] multiprocessing cannot spawn grandchild from a Windows service

2016-02-26 Thread Davin Potts

Davin Potts added the comment:

Attached is a patch for the 2.7 branch which adds the check described in the 
previous message.

I don't see a reasonable way to provide an accompanying test because it 
requires registering a win32 service (requiring administrative privileges) 
temporarily to attempt to provoke the issue.

Can I request that someone else run the full regression tests on this patch?  I 
am unable to complete a standard run of tests as my Windows 7 development 
system is set up for building Python 3.x (newer Visual Studio) and am hesitant 
to fight with Visual Studio configurations.

--
keywords: +patch
stage: needs patch -> patch review
Added file: 
http://bugs.python.org/file42034/issue_26434_fix_win32_service_parent_origin.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26434] multiprocessing cannot spawn grandchild from a Windows service

2016-02-25 Thread Marc Schlaich

New submission from Marc Schlaich:

This is a follow up of #5162.

There are some occasions where you can still run into this issue. One example 
is if you want to spawn a new multiprocessing.Process as a child of a 
multiprocessing.Process:

pythonservice.exe
  - multiprocessing.Process
- multiprocessing.Process (does not start!)


Attached is a test case. If you run this in pywin32 service debug mode, you see 
that the process crashes with:

Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\lib\multiprocessing\forking.py", line 380, in main
prepare(preparation_data)
  File "C:\Python27\lib\multiprocessing\forking.py", line 503, in prepare
file, path_name, etc = imp.find_module(main_name, dirs)
ImportError: No module named PythonService


In get_preparation_data is the following state:

  WINSERVICE: False
  WINEXE: False
  _python_exe: C:\Python27\python.exe


And so you get as preparation data:

  {'authkey': '...', 'sys_path': [...], 'name': 'test', 'orig_dir': '...', 
'sys_argv': ['C:\\Python27\\lib\\site-packages\\win32\\PythonService.exe'], 
'main_path': 'C:\\Python27\\lib\\site-packages\\win32\\PythonService.exe', 
'log_to_stderr': False}


A workaround for me is patching `get_preparation_data` as follows:

import multiprocessing.forking

_org_get_preparation_data = multiprocessing.forking.get_preparation_data

def _get_preparation_data(*args):
data = _org_get_preparation_data(*args)
main_path = data.get('main_path')
if main_path is not None and main_path.endswith('exe'):
data.pop('main_path')
return data

multiprocessing.forking.get_preparation_data = _get_preparation_data


BTW, the test case does not run on Python 3.5, but starting the service 
manually did work. So this is probably a Python 2 issue only.

--
components: Library (Lib), Windows
files: test_mp_service.py
messages: 260846
nosy: paul.moore, schlamar, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: multiprocessing cannot spawn grandchild from a Windows service
type: crash
versions: Python 2.7
Added file: http://bugs.python.org/file42025/test_mp_service.py

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26434>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25331] https://docs.python.org/3.5/using/windows.html should list whcih windows service packs are

2015-10-07 Thread Laura Creighton

New submission from Laura Creighton:

https://docs.python.org/3.5/using/windows.html should list which
windows service packs are needed to install Python.  Could somebody 
knowledgable please add this information.

--
assignee: docs@python
components: Documentation, Windows
messages: 252460
nosy: docs@python, lac, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: https://docs.python.org/3.5/using/windows.html should list whcih windows 
service packs are

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25331>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Windows service in production?

2015-03-20 Thread Raymond Cote
Years and years ago we found a module called ntsvc which allows us to run as a 
Service on Windows.
We’ve been using it since well before 2011 to build 32-bit services on Windows 
with py2exe.
If you contact me directly, I’ll dig it out of our source tree and post it on a 
shared location.

Alternatively, you may want to look at a service manager such as: 
https://nssm.cc
This allows you to run a standard executable as a Windows Service.
We’ve just started looking down this path ourselves since we’re looking to move 
to Python 3.x and want to reduce our dependencies as much as possible.
—Ray


 On Mar 19, 2015, at 2:58 AM, jyothi.n...@gmail.com wrote:
 
 On Tuesday, August 16, 2011 at 10:02:02 AM UTC+5:30, snorble wrote:
 Anyone know of a Python application running as a Windows service in
 production? I'm planning a network monitoring application that runs as
 a service and reports back to the central server. Sort of a heartbeat
 type agent to assist with this server is down, go check on it type
 situations.
 
 If using Visual Studio and C# is the more reliable way, then I'll go
 that route. I love Python, but everything I read about Python services
 seems to have workarounds ahoy for various situations (or maybe that's
 just Windows services in general?). And there seem to be multiple
 layers of workarounds, since it takes py2exe (or similar) and there
 are numerous workarounds required there, depending on which libraries
 and functionality are being used. Overall, reading about Windows
 services in Python is not exactly a confidence inspiring experience.
 If I knew of a reference example of something reliably running in
 production, I'd feel better than copying and pasting some code from a
 guy's blog.
 
 Have you got any resolution for creating a service in windows 7 32bit
 --
 https://mail.python.org/mailman/listinfo/python-list



signature.asc
Description: Message signed with OpenPGP using GPGMail
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2015-03-19 Thread jyothi . nadu
On Tuesday, August 16, 2011 at 10:02:02 AM UTC+5:30, snorble wrote:
 Anyone know of a Python application running as a Windows service in
 production? I'm planning a network monitoring application that runs as
 a service and reports back to the central server. Sort of a heartbeat
 type agent to assist with this server is down, go check on it type
 situations.
 
 If using Visual Studio and C# is the more reliable way, then I'll go
 that route. I love Python, but everything I read about Python services
 seems to have workarounds ahoy for various situations (or maybe that's
 just Windows services in general?). And there seem to be multiple
 layers of workarounds, since it takes py2exe (or similar) and there
 are numerous workarounds required there, depending on which libraries
 and functionality are being used. Overall, reading about Windows
 services in Python is not exactly a confidence inspiring experience.
 If I knew of a reference example of something reliably running in
 production, I'd feel better than copying and pasting some code from a
 guy's blog.

Have you got any resolution for creating a service in windows 7 32bit
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2015-03-19 Thread jyothi . nadu
On Tuesday, August 16, 2011 at 1:22:37 PM UTC+5:30, Tim Golden wrote:
 On 16/08/2011 05:32, snorble wrote:
  Anyone know of a Python application running as a Windows service in
  production? I'm planning a network monitoring application that runs as
  a service and reports back to the central server. Sort of a heartbeat
  type agent to assist with this server is down, go check on it type
  situations.
 
 Don't know what it'll take to inspire you with confidence, but I have
 several Python services running here without a hitch.
 The longest have been running for about three years -- not without
 a stop, since they have to be restarted for reasons external to the
 service itself.
 
 There's no py2exe involved, just the pywin32 service wrappers. (The
 apps in question are also set up to run standalone for testing etc.).
 They're mostly around a helpdesk system: one app ingests email requests
 to the helpdesk; another post-processes call changes, currently to
 send out email alerts to interested parties; another triggers alarms
 on calls for various purposes, etc.
 
 I don't claim they're the most sophisticated pieces of code on Earth,
 but it doesn't sound like you're after anything spectacular either.
 
 TJG



hello everyone,


I want to run a python file as a service in my windows7 , I am trying but not 
getting the proper sollution and i have written a script for this but not 
executing properly and i need to work this with postgresql


import win32service
import win32serviceutil
import win32api
import win32con
import win32event
import win32evtlogutil
import os, sys, string, time
'''
C:\python aservice.py  --username tarang --password 12345 --startup auto 
install
'''
class aservice(win32serviceutil.ServiceFramework):
   
   _svc_name_ = Trail Service
   _svc_display_name_ = Database Maintenance
   _svc_description_ = THis is what my crazy little service does - aka a 
DESCRIPTION! WHoa!
 
   def __init__(self, args):
   win32serviceutil.ServiceFramework.__init__(self, args)
   self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)  

   def SvcStop(self):
   self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
   win32event.SetEvent(self.hWaitStop)
 
   def SvcDoRun(self):
  import servicemanager  
  
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,servicemanager.PYS_SERVICE_STARTED,(self._svc_name_,
 ''))
 

  self.timeout = 12 #120 seconds / 2 minutes

  while 1:
 # 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(TrailVersion - STOPPED!)
break
 else:
   
 try:
 file_path = D:\Tarang\Project\form1.py
 execfile(file_path) 

 inc_file_path2 = D:\Tarang\Project\reter1.py
 execfile(inc_file_path2)

 inc_file_path2 = D:\Tarang\Project\exporting.py
 execfile(inc_file_path2)
 except:
 pass
 


def ctrlHandler(ctrlType):
   return True
 
if __name__ == '__main__':  
   win32api.SetConsoleCtrlHandler(ctrlHandler, True)  
   win32serviceutil.HandleCommandLine(aservice)

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2015-03-19 Thread Michiel Overtoom

On Mar 19, 2015, at 08:00, jyothi.n...@gmail.com wrote:

  file_path = D:\Tarang\Project\form1.py

Use either slashes (/), raw strings, or double backslashes:

file_path = D:/Tarang/Project/form1.py
file_path = rD:\Tarang\Project\form1.py
file_path = D:\\Tarang\\Project\\form1.py

-- 
You can't actually make computers run faster, you can only make them do less. 
- RiderOfGiraffes

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2015-03-19 Thread CHIN Dihedral

Please check wxpython and there was
 an example.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue5162] multiprocessing cannot spawn child from a Windows service

2015-01-07 Thread Marc Schlaich

Marc Schlaich added the comment:

This issue is not fully fixed, there are some occasions where you can still run 
into it. One example is if you want to spawn a new multiprocessing.Process as 
sub process in a multiprocessing.Process:


pythonservice.exe
  - multiprocessing.Process
- multiprocessing.Process (does not start!)

In this case you get:

  WINSERVICE: False
  WINEXE: False
  _python_exe: C:\Python27\python.exe
  prep data: {'authkey': '...', 'sys_path': [...], 'name': 'test', 'orig_dir': 
'...', 'sys_argv': 
['C:\\Python27\\lib\\site-packages\\win32\\PythonService.exe'], 'main_path': 
'C:\\Python27\\lib\\site-packages\\win32\\PythonService.exe', 'log_to_stderr': 
False}

--
nosy: +schlamar

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Python as Windows Service

2014-09-25 Thread Nagy László Zsolt



*De :*Gmail [mailto:mrje...@gmail.com]
*Envoyé :* Wednesday, September 24, 2014 2:41 PM
*À :* Arulnambi Nandagoban
*Objet :* Re: Python as Windows Service

Also, this may work for you

http://nssm.cc/description

http://nssm.cc/usage

NSSM installs an existing app as a service.


//Jean/



By the way, do we have support for creating a Windows Service for Python 
3 already? I know it was not working about 6 months ago. Does pywin32 
(PythonService.exe ?) still lack this feautue?


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python as Windows Service

2014-09-25 Thread Zachary Ware
On Thu, Sep 25, 2014 at 9:33 AM, Nagy László Zsolt gand...@shopzeus.com wrote:
 By the way, do we have support for creating a Windows Service for Python 3
 already? I know it was not working about 6 months ago. Does pywin32
 (PythonService.exe ?) still lack this feautue?

I can confirm that a Windows service can be created using the latest
py2exe (which supports Python 3.3+) with Python 3.4 and pywin32 build
219.  I assume that pythonservice.exe would also work, but I haven't
tried it on its own.

-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Python as Windows Service

2014-09-24 Thread Arulnambi Nandagoban
De : Gmail [mailto:mrje...@gmail.com] 
Envoyé : Wednesday, September 24, 2014 2:41 PM
À : Arulnambi Nandagoban
Objet : Re: Python as Windows Service

 

Also, this may work for you

 

http://nssm.cc/description

http://nssm.cc/usage

 

NSSM installs an existing app as a service.


/Jean

 


On Sep 24, 2014, at 3:16 AM, Arulnambi Nandagoban a.nandago...@traxens.com 
wrote:

De : MrJean1 [mailto:mrje...@gmail.com] 
Envoyé : Tuesday, September 23, 2014 5:55 PM
À : a.nandago...@traxens.com
Objet : Python as Windows Service

 

Here's one, simple example

 

http://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how

There are more, just search for Python Windows Service for example.


/Jean

 

 

Thank you !!! 

 

--

Nambi

 

 

Thank you again !!!

 

I managed to run the server as as service with help of sample code provided in 
http://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how
 .

I found some problem in stopping the service.  I feel it because of 
socket.accept() which blocks. This the class where I implemented the server in 
the main method.

 

 

class TraxServerSvc (win32serviceutil.ServiceFramework):

_svc_name_ = Testserver

_svc_display_name_ = Pytestserver

 

def __init__(self,args):


win32serviceutil.ServiceFramework.__init__(self,args)

self.hWaitStop = 
win32event.CreateEvent(None,0,0,None)

self.sloop = True

self.serversock = 0

 

def SvcStop(self):


self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)   

win32event.SetEvent(self.hWaitStop)

self.sloop = False

 

def SvcDoRun(self):


servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, 
servicemanager.PYS_SERVICE_STARTED, (self._svc_name_,''))

self.main()



def main(self):

self.serversock = socket.socket(socket.AF_INET, 
socket.SOCK_STREAM)

self.serversock.bind(server_config())

self.serversock.listen(5)   


while 
(win32event.WaitForSingleObject(self.hWaitStop, 0) == 258): 
   

try:

clientsock, 
addr = self.serversock.accept()


Pysconfig.logger.info('...connected from: %s', addr) # logging


thread.start_new_thread(handler, (clientsock, addr))


Pysconfig.logger.info('Thread ID: %s', thread.get_ident()) # logging
  

except socket.error, msg:


Pysconfig.logger.info('Failed to create socket. Error code: ' + str(msg[0]) + ' 
, Error message : ' + msg[1])

pass

self.serversock.shutdown(socket.SHUT_RDWR)

self.serversock.close()


servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, 
servicemanager.PYS_SERVICE_STOPPED, (self._svc_name_,''))

 

if __name__ == '__main__':

win32serviceutil.HandleCommandLine(TraxServerSvc)

 

When win32event.WaitForSingleObject(self.hWaitStop, 0) method returns zero , I 
need to quit the while loop to stop the service. But in the above case, since 
it blocks in accept , I need to make connection from client to completely stop 
service. 

 

--

nambi

 

 

 

 

 

 

-- 
https://mail.python.org/mailman/listinfo/python-list


tcp server as windows service

2014-09-23 Thread Arulnambi Nandagoban
Hello all, 

 

I developed a multithreaded tcp server with python and I converted into a
windows executable using pyinstaller. 

I would like to run the server as a windows service so that server restarts
whenever pc restarts without 

doing it manually . Help me out with some sample code . 

 

--

nambi 

 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tcp server as windows service

2014-09-23 Thread Johannes Findeisen
Hi,

On Tue, 23 Sep 2014 15:56:41 +0200
Arulnambi Nandagoban wrote:

 Hello all, 
 
  
 
 I developed a multithreaded tcp server with python and I converted into a
 windows executable using pyinstaller. 
 
 I would like to run the server as a windows service so that server restarts
 whenever pc restarts without 
 
 doing it manually . Help me out with some sample code . 

Take a look at this post:

https://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how

Read the comments below the solution to add your script to the Windows
services list.

I didn't do windows development but it seems very easy to do.

Regards,

Johannes
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python] Re: Windows service in production?

2011-08-18 Thread Chris Gonnerman
Chiming in late here, but I've been running a very simple Python service 
for some time now on a number of computers.  It's my Raw Print Server, 
available at 
http://newcenturycomputers.net/projects/rawprintserver.html, and I have 
instructions on the page for installing the Windows service version.  
It's really quite simple to do in plain Python; the only reason to use 
py2exe is if you don't want to install a full Python interpreter on the 
computer.  But since I generally do anyway, it doesn't matter to me.


-- Chris.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-18 Thread Grummble

On 08/16/2011 12:32 AM, snorble wrote:

Anyone know of a Python application running as a Windows service in
production? I'm planning a network monitoring application that runs as
a service and reports back to the central server. Sort of a heartbeat
type agent to assist with this server is down, go check on it type
situations.



I modified something similar to:
http://code.activestate.com/recipes/551780-win-services-helper/
and it was in production for several years without any issues.

Specifically it processed orders generated by a customer's MRP system, 
delivered to us via LPR, then processed into a format our in house 
windows hosted picking/shipping system could digest. Availability was a 
*major* requirement, and it worked flawlessly.




--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python] Re: Windows service in production?

2011-08-18 Thread Chris Gonnerman
Chiming in late here, but I've been running a very simple Python service 
for some time now on a number of computers.  It's my Raw Print Server, 
available at 
http://newcenturycomputers.net/projects/rawprintserver.html, and I have 
instructions on the page for installing the Windows service version. 
It's really quite simple to do in plain Python; the only reason to use 
py2exe is if you don't want to install a full Python interpreter on the 
computer.  But since I generally do anyway, it doesn't matter to me.


-- Chris.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-18 Thread Stephen Hansen
On 8/15/11 9:32 PM, snorble wrote:
 Anyone know of a Python application running as a Windows service in
 production? I'm planning a network monitoring application that runs as
 a service and reports back to the central server. Sort of a heartbeat
 type agent to assist with this server is down, go check on it type
 situations.
 
 If using Visual Studio and C# is the more reliable way, then I'll go
 that route. I love Python, but everything I read about Python services
 seems to have workarounds ahoy for various situations (or maybe that's
 just Windows services in general?). And there seem to be multiple
 layers of workarounds, since it takes py2exe (or similar) and there
 are numerous workarounds required there, depending on which libraries
 and functionality are being used. Overall, reading about Windows
 services in Python is not exactly a confidence inspiring experience.
 If I knew of a reference example of something reliably running in
 production, I'd feel better than copying and pasting some code from a
 guy's blog.

Belatedly: I run a few quite major windows services which are installed
at various customer sites in production, and we have no issues with it
being a windows service.

I basically only ever ran into two problems:

 1. The lack of a console. Your service flat out /does not have/ a
console, which is a slightly weird state to be in: writing to sys.stdout
will fail. A print statement left in can crash things up -- even if in
third-party code.

Now, once you realize this is there, its easy to fix. I end up
doing something like this very early on in processing:

class FakeFile:
def __init__(self, fp):
self._fp = fp
def write(self, data):
try:
self._fp.write(data)
except:
pass

# repeat with flush()

sys.stdout = FakeFile(sys.stdout)
sys.stderr = FakeFile(sys.stderr)

That way it'll run from a regular terminal fine and write out fine,
but if any stray attempts to print are left in, things will pass through
fine when its running as a service.

  2. Importing modules with the same names as dlls in system32 can go
awry. I don't know if this is still there, I last touched this part of
our code a long, long, long time ago: but my service does some manual
PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy
to do.

It worked fine, and was stable and once going, everything worked fine.

Ultimately, I have since abandoned running things as a real service
directly, and wrote a Metaservice application we use in our company
instead. It runs as a service, and executes any random series of
programs beneath it, creating JOB's for each so any subprocesses of they
launch all get killed together cleanly, and handling dependencies via
between them through various means, and stuff like that. I just got
tired of dealing with windows stuff, so. :)

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-18 Thread Adam Jorgensen
Yeah, we run our Python App as a service under Windows.

You can look at the open-souce part of our product using
http://trac.sjsoft.com/browser
If you look into the code you should be able to find some stuff to do with
services.

Specficially, look in trunk/j5/src/j5/OS/WinService.py

On 19 August 2011 07:00, Stephen Hansen me+list/pyt...@ixokai.io wrote:

 On 8/15/11 9:32 PM, snorble wrote:
  Anyone know of a Python application running as a Windows service in
  production? I'm planning a network monitoring application that runs as
  a service and reports back to the central server. Sort of a heartbeat
  type agent to assist with this server is down, go check on it type
  situations.
 
  If using Visual Studio and C# is the more reliable way, then I'll go
  that route. I love Python, but everything I read about Python services
  seems to have workarounds ahoy for various situations (or maybe that's
  just Windows services in general?). And there seem to be multiple
  layers of workarounds, since it takes py2exe (or similar) and there
  are numerous workarounds required there, depending on which libraries
  and functionality are being used. Overall, reading about Windows
  services in Python is not exactly a confidence inspiring experience.
  If I knew of a reference example of something reliably running in
  production, I'd feel better than copying and pasting some code from a
  guy's blog.

 Belatedly: I run a few quite major windows services which are installed
 at various customer sites in production, and we have no issues with it
 being a windows service.

 I basically only ever ran into two problems:

  1. The lack of a console. Your service flat out /does not have/ a
 console, which is a slightly weird state to be in: writing to sys.stdout
 will fail. A print statement left in can crash things up -- even if in
 third-party code.

Now, once you realize this is there, its easy to fix. I end up
 doing something like this very early on in processing:

class FakeFile:
def __init__(self, fp):
self._fp = fp
def write(self, data):
try:
self._fp.write(data)
except:
pass

# repeat with flush()

sys.stdout = FakeFile(sys.stdout)
sys.stderr = FakeFile(sys.stderr)

That way it'll run from a regular terminal fine and write out fine,
 but if any stray attempts to print are left in, things will pass through
 fine when its running as a service.

  2. Importing modules with the same names as dlls in system32 can go
 awry. I don't know if this is still there, I last touched this part of
 our code a long, long, long time ago: but my service does some manual
 PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy
 to do.

 It worked fine, and was stable and once going, everything worked fine.

 Ultimately, I have since abandoned running things as a real service
 directly, and wrote a Metaservice application we use in our company
 instead. It runs as a service, and executes any random series of
 programs beneath it, creating JOB's for each so any subprocesses of they
 launch all get killed together cleanly, and handling dependencies via
 between them through various means, and stuff like that. I just got
 tired of dealing with windows stuff, so. :)

 --

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/


 --
 http://mail.python.org/mailman/listinfo/python-list


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-17 Thread Tim Golden

On 16/08/2011 15:46, snorble wrote:

Interesting. Normally I would use py2exe then do myapp.exe -install
to install the app as a service. How do you handle installing the
service? Also what does the service show under the properties, for the
executable? python.exe script.py or something else?


To install, I simply invoke the Command-line handler which comes with 
the pywin32 service utils:


if __name__ == '__main__':
  win32serviceutil.HandleCommandLine (Service)

(I imagine that's what py2exe's doing for you behind the scenes).

The executable shows as pythonservice.exe. The short and long
display names can of course be whatever you like.

TJG
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-16 Thread Tim Golden

On 16/08/2011 05:32, snorble wrote:

Anyone know of a Python application running as a Windows service in
production? I'm planning a network monitoring application that runs as
a service and reports back to the central server. Sort of a heartbeat
type agent to assist with this server is down, go check on it type
situations.


Don't know what it'll take to inspire you with confidence, but I have
several Python services running here without a hitch.
The longest have been running for about three years -- not without
a stop, since they have to be restarted for reasons external to the
service itself.

There's no py2exe involved, just the pywin32 service wrappers. (The
apps in question are also set up to run standalone for testing etc.).
They're mostly around a helpdesk system: one app ingests email requests
to the helpdesk; another post-processes call changes, currently to
send out email alerts to interested parties; another triggers alarms
on calls for various purposes, etc.

I don't claim they're the most sophisticated pieces of code on Earth,
but it doesn't sound like you're after anything spectacular either.

TJG
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-16 Thread alex23
snorble snor...@hotmail.com wrote:
 If using Visual Studio and C# is the more reliable way, then I'll go
 that route. I love Python, but everything I read about Python services
 seems to have workarounds ahoy for various situations (or maybe that's
 just Windows services in general?).

What workarounds do you mean? Every example I've ever seen makes
direct use of the Windows modules for Python.

 And there seem to be multiple
 layers of workarounds, since it takes py2exe (or similar) and there
 are numerous workarounds required there, depending on which libraries
 and functionality are being used.

What about existing code recipes which were featured in the Python
Cookbook?

http://code.activestate.com/recipes/551780/

Not a hint of pyexe or weird hackery.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-16 Thread aspineux
On Aug 16, 6:32 am, snorble snor...@hotmail.com wrote:
 Anyone know of a Python application running as a Windows service in
 production? I'm planning a network monitoring application that runs as
 a service and reports back to the central server. Sort of a heartbeat
 type agent to assist with this server is down, go check on it type
 situations.

I don't use service for my own python applications, even standalone
py2exe applications.
I use the Windows taskscheduler that start it once and try every
minute to start it again
but is is running all the time, and the the scheduler does nothing and
wait to see for the next minute.
When the python program crash then the scheduler restart it in the
minute.

look here how I do with tcpproxyreflector:
http://blog.magiksys.net/software/tcp-proxy-reflector#tcpr_service

In My MKSBackup  http://blog.magiksys.net/mksbackup-quick-overview
I have a install() function that create the task in the scheduler for
XP and Windows2008

And this code, use a 2 min interval


print 'create task %s in scheduler' % (task_name, )
interval=raw_input_with_default('Enter interval in minutes',
'', str(interval_in_minutes))
cmd='%s -c %s' % (os.path.join(install_target,
os.path.basename(sys.argv[0])), os.path.join(target, ini_file))
schtasks_cmd=[ 'SCHTASKS', '/Create', '/SC', 'MINUTE', '/MO',
interval, '/TN', task_name, '/RU', os.getenv('USERNAME'), '/TR', cmd ]
if sys.getwindowsversion()[0]5:
# under 2008 ? require HIGHEST privilege
# schtasks_cmd.insert(2, 'HIGHEST')
# schtasks_cmd.insert(2, '/RL')
# under 2008, to force the system to ask for the password,
set empty password
i=schtasks_cmd.index('/RU')+2
schtasks_cmd.insert(i, '')
schtasks_cmd.insert(i, '/RP')
else:
pass


Mix all 3 source to get what you want.

Services are probably fine too, but this is another story.



 If using Visual Studio and C# is the more reliable way, then I'll go
 that route. I love Python, but everything I read about Python services
 seems to have workarounds ahoy for various situations (or maybe that's
 just Windows services in general?). And there seem to be multiple
 layers of workarounds, since it takes py2exe (or similar) and there
 are numerous workarounds required there, depending on which libraries
 and functionality are being used. Overall, reading about Windows
 services in Python is not exactly a confidence inspiring experience.
 If I knew of a reference example of something reliably running in
 production, I'd feel better than copying and pasting some code from a
 guy's blog.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-16 Thread snorble
On Aug 16, 2:52 am, Tim Golden m...@timgolden.me.uk wrote:
 On 16/08/2011 05:32, snorble wrote:

  Anyone know of a Python application running as a Windows service in
  production? I'm planning a network monitoring application that runs as
  a service and reports back to the central server. Sort of a heartbeat
  type agent to assist with this server is down, go check on it type
  situations.

 Don't know what it'll take to inspire you with confidence, but I have
 several Python services running here without a hitch.
 The longest have been running for about three years -- not without
 a stop, since they have to be restarted for reasons external to the
 service itself.

 There's no py2exe involved, just the pywin32 service wrappers. (The
 apps in question are also set up to run standalone for testing etc.).
 They're mostly around a helpdesk system: one app ingests email requests
 to the helpdesk; another post-processes call changes, currently to
 send out email alerts to interested parties; another triggers alarms
 on calls for various purposes, etc.

 I don't claim they're the most sophisticated pieces of code on Earth,
 but it doesn't sound like you're after anything spectacular either.

 TJG

Interesting. Normally I would use py2exe then do myapp.exe -install
to install the app as a service. How do you handle installing the
service? Also what does the service show under the properties, for the
executable? python.exe script.py or something else?
-- 
http://mail.python.org/mailman/listinfo/python-list


Windows service in production?

2011-08-15 Thread snorble
Anyone know of a Python application running as a Windows service in
production? I'm planning a network monitoring application that runs as
a service and reports back to the central server. Sort of a heartbeat
type agent to assist with this server is down, go check on it type
situations.

If using Visual Studio and C# is the more reliable way, then I'll go
that route. I love Python, but everything I read about Python services
seems to have workarounds ahoy for various situations (or maybe that's
just Windows services in general?). And there seem to be multiple
layers of workarounds, since it takes py2exe (or similar) and there
are numerous workarounds required there, depending on which libraries
and functionality are being used. Overall, reading about Windows
services in Python is not exactly a confidence inspiring experience.
If I knew of a reference example of something reliably running in
production, I'd feel better than copying and pasting some code from a
guy's blog.
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue5162] multiprocessing cannot spawn child from a Windows service

2011-04-18 Thread Brian Curtin

Changes by Brian Curtin br...@python.org:


--
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2011-04-11 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
components: +Windows
nosy: +brian.curtin, tim.golden
versions: +Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2011-04-11 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
stage: test needed - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2011-04-11 Thread Brian Curtin

Brian Curtin br...@python.org added the comment:

This looks reasonable to me. If no one beats me to it, I'll check it in tonight.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2011-04-11 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset 1f41b1ab8924 by brian.curtin in branch '3.1':
Fix #5162. Allow child spawning from Windows services (via pywin32).
http://hg.python.org/cpython/rev/1f41b1ab8924

New changeset 184ae02e3221 by brian.curtin in branch '3.2':
Fix #5162. Allow child spawning from Windows services (via pywin32).
http://hg.python.org/cpython/rev/184ae02e3221

New changeset 3c2bdea18b5c by brian.curtin in branch 'default':
Fix #5162. Allow child spawning from Windows services (via pywin32).
http://hg.python.org/cpython/rev/3c2bdea18b5c

New changeset 6507a5ba5c27 by brian.curtin in branch '2.7':
Fix #5162. Allow child spawning from Windows services (via pywin32).
http://hg.python.org/cpython/rev/6507a5ba5c27

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2011-04-11 Thread Brian Curtin

Brian Curtin br...@python.org added the comment:

Thanks for the patch!

--
assignee: jnoller - brian.curtin
resolution:  - fixed
stage: patch review - committed/rejected

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2011-04-11 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset a280672d3d8d by brian.curtin in branch '2.7':
Add NEWS item for #5162.
http://hg.python.org/cpython/rev/a280672d3d8d

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2011-04-11 Thread Roundup Robot

Roundup Robot devnull@devnull added the comment:

New changeset c26474c6504a by brian.curtin in branch '3.1':
Add NEWS item for #5162.
http://hg.python.org/cpython/rev/c26474c6504a

New changeset 68ef2bf1aa99 by brian.curtin in branch '3.2':
Add NEWS item for #5162.
http://hg.python.org/cpython/rev/68ef2bf1aa99

New changeset 2c4043070f05 by brian.curtin in branch 'default':
Add NEWS item for #5162.
http://hg.python.org/cpython/rev/2c4043070f05

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2011-01-03 Thread Mher Movsisyan

Mher Movsisyan mher.movsis...@gmail.com added the comment:

Attached test case demonstrates the issue.

--
nosy: +mher
Added file: http://bugs.python.org/file20240/test_issue5162.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2011-01-03 Thread Mher Movsisyan

Mher Movsisyan mher.movsis...@gmail.com added the comment:

Treating python services like frozen executables solves the issue. The patch is 
attached.

--
Added file: http://bugs.python.org/file20241/forking_r87679.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Help needed with Windows Service in Python

2010-09-23 Thread Aahz
In article mailman.376.1283440944.29448.python-l...@python.org,
Ian Hobson  i...@ianhobson.co.uk wrote:

I am attempting to create a Windows Service in Python.

BTW, you probably want to subscribe to 
http://mail.python.org/mailman/listinfo/python-win32
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur.  --Red Adair
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue9503] print statement hangs Windows service

2010-09-10 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc amaur...@gmail.com added the comment:

Closing as a duplicate of issue706263.

Instead of changing all print statements, you could set sys.stdout to another 
file, for example:
sys.stdout=StringIO()
or another object that simply discards written data.

--
nosy: +amaury.forgeotdarc
resolution:  - duplicate
status: open - closed
superseder:  - print raises exception when no console available

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9503
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



redirecting stdout and stderr for a windows service

2010-09-06 Thread Ian Hobson

Hi all,

I am trying to redirect stdout and stderr on a python  windows service, 
so that the service will not stall after 256 chars is written, and so I 
can use print for simple debugging.


I have the following 4 lines (copy/pasted) in the source of my code.

if __name__ == '__main__':
sys.stdout = sys.stderr = open(d:\logfile.txt, a)
print Starting up
win32serviceutil.HandleCommandLine(PythonService)

When I run them as a free standing program, logfile.txt is created
the text placed in it, and it crashed on the last line - no permissions 
to create a service. (Micro-cluless has no sudo command in Win7. :( )


When I start the code as a service, it does not create the log file
does not put anything in it, but the last line is executed and the 
service starts! There are no Events on the event log.


When I stop the service, it stops. Still no log file. Still no events.

I tried running the service with my account and not the system user. 
This gave me run as service permissions, but did not alter the results.


What is happening?

And how can I set up logging so that the service can simply restart, 
leaving the trackback in the log file for me to come to later.


All help gratefully received. I've lost most of my remaining hair today 
on this one.


Ian







--
http://mail.python.org/mailman/listinfo/python-list


Re: redirecting stdout and stderr for a windows service

2010-09-06 Thread Ulrich Eckhardt
Ian Hobson wrote:
  sys.stdout = sys.stderr = open(d:\logfile.txt, a)

\l is probably not what you want. Consider using \\l or r\l instead.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: redirecting stdout and stderr for a windows service

2010-09-06 Thread Ian

 On 06/09/2010 15:29, Ian Hobson wrote:

Hi all,


Forget this.

The problem is that it is a Windows Service, so it is not initialised in 
the normal way.


PythonService.exe loads other code (named __main__) that loads the 
service proper, so the

if test was never true!

Regards

Ian
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-03 Thread Ian

 On 03/09/2010 01:38, Mark Hammond wrote:
I expect that the Windows Event Log might have some clues, as would 
attempting to use it in debug mode. 

Thanks Mark.

The error log holds the trackback - it identified the line with the typo.

Now the typo is fixed, the service starts and stops properly.

Regards

Ian
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-03 Thread Ian

 On 02/09/2010 20:55, Edward Kozlowski wrote:

On Sep 2, 2:38 pm, Ianhobso...@gmaiil.com  wrote:

   On 02/09/2010 20:06, Edward Kozlowski wrote:




On Sep 2, 10:22 am, Ian Hobsoni...@ianhobson.co.ukwrote:

Hi All,
I am attempting to create a Windows Service in Python.
I have the framework (from Mark Hammond and Andy Robinason's book)
running - see below. It starts fine - but it will not stop. :(
net stop Python Service
and using the services GUI both leave the services showing it as stopping
I guess this means SvcStop is called but it is not enough to get it out
of the machine.
Does anyone know why not?
Python 2.7 with win32 extensions, sunning on Windows 7.
Many thanks
Ian
the (complete) source code is
#!/usr/bin/env python
# coding=utf8
#   service.py  = testing services and Named pipes
#
import win32serviceutil
import win32service
import win32event
class PythonService(win32serviceutil.ServiceFramework):
 _svc_name_ = Python Service
 _svc_display_name_ = Test Service in Python
 def __init__(self, args):
   win32serviceutil.ServiceFramework.__init__(self,args)
   self.hWaitStop = win32event.CreateEvent(None,0,0,None)
 def SvcStop(self):
   self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
   wind32event.SetEvent(self.hWaitStop)
 def SvcDoRun(self):
   win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE)
if __name__ == '__main__':
 win32serviceutil.HandleCommandLine(PythonService)

Looks to me like there may be a typo in your code.
You probably meant win32event.SetEvent(self.hWaitStop), not
wind32event.
Regards,
-Edward Kozlowski

A huge big thank you Edward.  That was the problem.

Regards

Ian

You're most welcome.

If you're looking at running services in Windows using Python, one
other hangup I ran into was that my services would freeze for no
reason.  At Pycon '09, I learned that there were buffers for stdout
and stderr that were filling.  I wish I could remember who gave the
talk that included the jewel of knowledge, because I'd love to give
credit where it's due...

After I redirected stdout and stderr to files, my problems with the
services freezing went away.

Regards,
-Edward Kozlowski

Hi Edward,

Thanks for the heads up. That is really worth knowing.

Ian


--
http://mail.python.org/mailman/listinfo/python-list


Help needed with Windows Service in Python

2010-09-02 Thread Ian Hobson

Hi All,

I am attempting to create a Windows Service in Python.

I have the framework (from Mark Hammond and Andy Robinason's book) 
running - see below. It starts fine - but it will not stop. :(


net stop Python Service

and using the services GUI both leave the services showing it as stopping

I guess this means SvcStop is called but it is not enough to get it out 
of the machine.


Does anyone know why not?

Python 2.7 with win32 extensions, sunning on Windows 7.

Many thanks

Ian

the (complete) source code is
#!/usr/bin/env python
# coding=utf8
#   service.py  = testing services and Named pipes
#
import win32serviceutil
import win32service
import win32event
class PythonService(win32serviceutil.ServiceFramework):
  _svc_name_ = Python Service
  _svc_display_name_ = Test Service in Python
  def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None,0,0,None)
  def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
wind32event.SetEvent(self.hWaitStop)
  def SvcDoRun(self):
win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE)
if __name__ == '__main__':
  win32serviceutil.HandleCommandLine(PythonService)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-02 Thread David
Il Thu, 02 Sep 2010 16:22:04 +0100, Ian Hobson ha scritto:

 self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)

You may try to give a WaitHint parameter to ReportServiceStatus call,
otherwise the Service Manager will expect the service is stopped istantly.

self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 1000)


David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-02 Thread ipatrol6...@yahoo.com
Well for one, if you're writing with pywin32, you certainly don't need the 
shbang line. #! /usr/bin/env is purely a POSIX thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-02 Thread Ian

 On 02/09/2010 18:03, David wrote:

Il Thu, 02 Sep 2010 16:22:04 +0100, Ian Hobson ha scritto:


self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)

You may try to give a WaitHint parameter to ReportServiceStatus call,
otherwise the Service Manager will expect the service is stopped istantly.

self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 1000)


David

Thanks David.

Sadly that makes no difference.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-02 Thread Edward Kozlowski
On Sep 2, 10:22 am, Ian Hobson i...@ianhobson.co.uk wrote:
 Hi All,

 I am attempting to create a Windows Service in Python.

 I have the framework (from Mark Hammond and Andy Robinason's book)
 running - see below. It starts fine - but it will not stop. :(

 net stop Python Service

 and using the services GUI both leave the services showing it as stopping

 I guess this means SvcStop is called but it is not enough to get it out
 of the machine.

 Does anyone know why not?

 Python 2.7 with win32 extensions, sunning on Windows 7.

 Many thanks

 Ian

 the (complete) source code is
 #!/usr/bin/env python
 # coding=utf8
 #   service.py  = testing services and Named pipes
 #
 import win32serviceutil
 import win32service
 import win32event
 class PythonService(win32serviceutil.ServiceFramework):
    _svc_name_ = Python Service
    _svc_display_name_ = Test Service in Python
    def __init__(self, args):
      win32serviceutil.ServiceFramework.__init__(self,args)
      self.hWaitStop = win32event.CreateEvent(None,0,0,None)
    def SvcStop(self):
      self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
      wind32event.SetEvent(self.hWaitStop)
    def SvcDoRun(self):
      win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE)
 if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(PythonService)

Looks to me like there may be a typo in your code.

You probably meant win32event.SetEvent(self.hWaitStop), not
wind32event.

Regards,
-Edward Kozlowski
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-02 Thread Ian

 On 02/09/2010 20:06, Edward Kozlowski wrote:

On Sep 2, 10:22 am, Ian Hobsoni...@ianhobson.co.uk  wrote:

Hi All,

I am attempting to create a Windows Service in Python.

I have the framework (from Mark Hammond and Andy Robinason's book)
running - see below. It starts fine - but it will not stop. :(

net stop Python Service

and using the services GUI both leave the services showing it as stopping

I guess this means SvcStop is called but it is not enough to get it out
of the machine.

Does anyone know why not?

Python 2.7 with win32 extensions, sunning on Windows 7.

Many thanks

Ian

the (complete) source code is
#!/usr/bin/env python
# coding=utf8
#   service.py  = testing services and Named pipes
#
import win32serviceutil
import win32service
import win32event
class PythonService(win32serviceutil.ServiceFramework):
_svc_name_ = Python Service
_svc_display_name_ = Test Service in Python
def __init__(self, args):
  win32serviceutil.ServiceFramework.__init__(self,args)
  self.hWaitStop = win32event.CreateEvent(None,0,0,None)
def SvcStop(self):
  self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
  wind32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
  win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(PythonService)

Looks to me like there may be a typo in your code.

You probably meant win32event.SetEvent(self.hWaitStop), not
wind32event.

Regards,
-Edward Kozlowski

A huge big thank you Edward.  That was the problem.

Regards

Ian
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-02 Thread Edward Kozlowski
On Sep 2, 2:38 pm, Ian hobso...@gmaiil.com wrote:
   On 02/09/2010 20:06, Edward Kozlowski wrote:



  On Sep 2, 10:22 am, Ian Hobsoni...@ianhobson.co.uk  wrote:
  Hi All,

  I am attempting to create a Windows Service in Python.

  I have the framework (from Mark Hammond and Andy Robinason's book)
  running - see below. It starts fine - but it will not stop. :(

  net stop Python Service

  and using the services GUI both leave the services showing it as stopping

  I guess this means SvcStop is called but it is not enough to get it out
  of the machine.

  Does anyone know why not?

  Python 2.7 with win32 extensions, sunning on Windows 7.

  Many thanks

  Ian

  the (complete) source code is
  #!/usr/bin/env python
  # coding=utf8
  #   service.py  = testing services and Named pipes
  #
  import win32serviceutil
  import win32service
  import win32event
  class PythonService(win32serviceutil.ServiceFramework):
      _svc_name_ = Python Service
      _svc_display_name_ = Test Service in Python
      def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self,args)
        self.hWaitStop = win32event.CreateEvent(None,0,0,None)
      def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        wind32event.SetEvent(self.hWaitStop)
      def SvcDoRun(self):
        win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE)
  if __name__ == '__main__':
      win32serviceutil.HandleCommandLine(PythonService)
  Looks to me like there may be a typo in your code.

  You probably meant win32event.SetEvent(self.hWaitStop), not
  wind32event.

  Regards,
  -Edward Kozlowski

 A huge big thank you Edward.  That was the problem.

 Regards

 Ian

You're most welcome.

If you're looking at running services in Windows using Python, one
other hangup I ran into was that my services would freeze for no
reason.  At Pycon '09, I learned that there were buffers for stdout
and stderr that were filling.  I wish I could remember who gave the
talk that included the jewel of knowledge, because I'd love to give
credit where it's due...

After I redirected stdout and stderr to files, my problems with the
services freezing went away.

Regards,
-Edward Kozlowski
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed with Windows Service in Python

2010-09-02 Thread Mark Hammond

On 3/09/2010 1:22 AM, Ian Hobson wrote:

Hi All,

I am attempting to create a Windows Service in Python.

I have the framework (from Mark Hammond and Andy Robinason's book)
running - see below. It starts fine - but it will not stop. :(

net stop Python Service

and using the services GUI both leave the services showing it as stopping

I guess this means SvcStop is called but it is not enough to get it out
of the machine.

Does anyone know why not?


I expect that the Windows Event Log might have some clues, as would 
attempting to use it in debug mode.



def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
wind32event.SetEvent(self.hWaitStop)


Note the typo in the line above...

Mark
--
http://mail.python.org/mailman/listinfo/python-list


[issue9503] print statement hangs Windows service

2010-08-10 Thread Florent Xicluna

Changes by Florent Xicluna florent.xicl...@gmail.com:


--
components: +Windows

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9503
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9503] print statement hangs Windows service

2010-08-04 Thread rgpitts

New submission from rgpitts richard.pi...@cdl.co.uk:

OS: Windows 2003 Server R2 x64 Standard Edition
Python: 2.6.5
MSVC: 9.0
Application Description: Windows service calling Python C API to run algorithm 
written in Python.

I've been encountering a random application hang when calling the Python C API 
function PyObject_CallMethod to call a function on a class instance. I've 
discovered that the C function fwrite in string_print in stringobject.c is 
blocking after being called multiple times due to print statements in Python 
code. My application as a Windows service does not have a stdout and fwrite is 
buffering data before attempting to write it to a non-existent stdout, thus 
blocking and hanging the service. This isn't an issue when the application has 
a console window because stdout is available.

We are in the process changing the print statements to write to file. Ideally a 
Python exception needs raising if print cannot write to stdout.

--
components: Interpreter Core
messages: 112768
nosy: rgpitts
priority: normal
severity: normal
status: open
title: print statement hangs Windows service
type: behavior
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9503
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9503] print statement hangs Windows service

2010-08-04 Thread Tim Golden

Changes by Tim Golden m...@timgolden.me.uk:


--
nosy: +tim.golden

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9503
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9503] print statement hangs Windows service

2010-08-04 Thread Eric Smith

Changes by Eric Smith e...@trueblade.com:


--
nosy: +eric.smith

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9503
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue9503] print statement hangs Windows service

2010-08-04 Thread rgpitts

rgpitts richard.pi...@cdl.co.uk added the comment:

I've created a test service that demostrates the problem. The example service 
calls PyRun_SimpleString in loop that evaluates the Python statement print 
'String'. The number of iteration in the loop depends on the length of the 
string used in the print statement. The longer the string the fewer iteration.

Attached is a Visual Studio 2008 project and readme.

--
Added file: http://bugs.python.org/file18373/PythonService.zip

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue9503
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2010-07-10 Thread Mark Lawrence

Changes by Mark Lawrence breamore...@yahoo.co.uk:


--
versions: +Python 2.7, Python 3.1, Python 3.2 -Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Executing Commands From Windows Service

2010-02-12 Thread T
On Feb 11, 4:10 am, Tim Golden m...@timgolden.me.uk wrote:
 On 10/02/2010 22:55, T wrote:

  Great suggestions once again - I did verify that it was at least
  running the plink.exe binary when under LocalSystem by having the
  service run plink.exe  C:\plinkoutput.txt - this worked fine.  And,
  as I mentioned, it's now working just fine when running under a
  regular admin account.  So, I think that's going to be my solution to
  avoid any further issues.  My best guess at this point (as you
  mentioned), is that plink.exe is doing _something_ network-related
  that LocalSystem doesn't have the privileges to do - what exactly it
  is, I have no idea.  I may play around with it some more later, but
  running the service under an admin account should be a perfectly
  acceptable solution.

  Also, I will be writing other Python apps that the service will be
  executing - so it goes without saying that I'll be including a log to
  file option :)  Thanks again for all your guys' help!

 I'm not sure if this has been said already, but a reasonably common
 approach to services is to create a user specifically for the
 service and grant it exactly the privs / perms it needs (once you
 work out what they are). You then assign it a generated password,
 eg a GUID which you don't even try to remember: simply cut-and-paste
 it in. Then create the service to run under that user.

 That way you don't have the service running under
 some local Administrator account with the associated risk
 of its being subverted and gaining more control than you
 want. Nor do you have it running as a real user whose
 password might change for any reason, leaving you with
 a service which won't start up.

 I don't remember at this moment whether such a user's profile
 is automatically loaded in the process when the service starts
 or whether you have to do the LoadUserProfile thing.

 TJG

Tim - thanks, that's the route I'm going to go.  I've created separate
accounts for services before, and there's no question that's what I
have to do in this case. I'm still having some issues running some
commands (such as one that takes a screenshot), even as an admin user,
but I think this is more due to the fact that it's trying to interact
with the Desktop..so there may be no good solution.

Btw great site..can't tell you how many times I've gone back to it.
Keep up the great work!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-12 Thread T
On Feb 11, 8:21 am, Martin P. Hellwig martin.hell...@dcuktec.org
wrote:
 On 02/07/10 19:02, T wrote:

  I have a script, which runs as a Windows service under the LocalSystem
  account, that I wish to have execute some commands.  Specifically, the
  program will call plink.exe to create a reverse SSH tunnel.  Right now
  I'm using subprocess.Popen to do so.  When I run it interactively via
  an admin account, all is well.  However, when I'm running it via
  service, no luck.  I'm assuming this is to do with the fact that it's
  trying to run under the LocalSystem account, which is failing.  What
  would be the best way around this?  Thanks!

 All being said about LS account not having the appropriate rights to
 access the necessary devices/files.

 Could it be so simple that the network is plain simply not available at
 all? For wireless connections I believe the connection/authentication by
 default is made in user space. I would save the output of an ipconfig
 run as the LS account to a file and see what is happening.
 Perhaps followed by a ping.

 --
 mph

Martin - another part of the program sends an email back to a
specified user, and that works, so LocalSystem must at least have some
network access.  From the testing I've done so far, seems like there's
just some grey area (which I haven't completely figured out yet) of
network-related tasks that LS just can't do.  I'd love to know what
this is, but so far the solution I have is just to create another user
and have the service use that..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-11 Thread Tim Golden

On 10/02/2010 22:55, T wrote:

Great suggestions once again - I did verify that it was at least
running the plink.exe binary when under LocalSystem by having the
service run plink.exe  C:\plinkoutput.txt - this worked fine.  And,
as I mentioned, it's now working just fine when running under a
regular admin account.  So, I think that's going to be my solution to
avoid any further issues.  My best guess at this point (as you
mentioned), is that plink.exe is doing _something_ network-related
that LocalSystem doesn't have the privileges to do - what exactly it
is, I have no idea.  I may play around with it some more later, but
running the service under an admin account should be a perfectly
acceptable solution.

Also, I will be writing other Python apps that the service will be
executing - so it goes without saying that I'll be including a log to
file option :)  Thanks again for all your guys' help!


I'm not sure if this has been said already, but a reasonably common
approach to services is to create a user specifically for the
service and grant it exactly the privs / perms it needs (once you
work out what they are). You then assign it a generated password,
eg a GUID which you don't even try to remember: simply cut-and-paste
it in. Then create the service to run under that user.

That way you don't have the service running under
some local Administrator account with the associated risk
of its being subverted and gaining more control than you
want. Nor do you have it running as a real user whose
password might change for any reason, leaving you with
a service which won't start up.

I don't remember at this moment whether such a user's profile
is automatically loaded in the process when the service starts
or whether you have to do the LoadUserProfile thing.

TJG
--
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-11 Thread Martin P. Hellwig

On 02/07/10 19:02, T wrote:

I have a script, which runs as a Windows service under the LocalSystem
account, that I wish to have execute some commands.  Specifically, the
program will call plink.exe to create a reverse SSH tunnel.  Right now
I'm using subprocess.Popen to do so.  When I run it interactively via
an admin account, all is well.  However, when I'm running it via
service, no luck.  I'm assuming this is to do with the fact that it's
trying to run under the LocalSystem account, which is failing.  What
would be the best way around this?  Thanks!


All being said about LS account not having the appropriate rights to 
access the necessary devices/files.


Could it be so simple that the network is plain simply not available at 
all? For wireless connections I believe the connection/authentication by 
default is made in user space. I would save the output of an ipconfig 
run as the LS account to a file and see what is happening.

Perhaps followed by a ping.

--
mph
--
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-10 Thread T
On Feb 9, 4:25 pm, David Bolen db3l@gmail.com wrote:
 David Bolen db3l@gmail.com writes:
  Not from my past experience - the system account (LocalSystem for
  services) can be surprising, in that it's pretty much unlimited access
  to all local resources, but severely limited in a handful of cases,
  one of which is any attempt to access the network.  I can't recall for
  sure if it's an absolute block, or if in some cases you can configure
  around it (e.g., it might use a null session for remote shares which
  can be enabled through the registry on the target machine).  I've
  basically stuck LocalSystem = no network in my head from past
  experience.

 Given it's been a few years, I decided to try some tests, and the
 above is too simplistic.

 The LocalSystem account runs without any local Windows credentials
 (e.g., not like a logged in user), which has several consequences.
 One is that you can't access any network resources that require such
 credentials (like shares).  However, there's no sort of firewall
 filtering or anything, so plain old TCP/IP connections are fine.
 Unless, of course, the client being used also has other needs for
 local Windows credentials, independent or as a pre-requisite to the
 network operations.

 So backing up a bit, the TCP/IP connection that plink is making is not
 inherently disabled by running under LocalSystem, but it's certainly
 possible that plink is trying to identify the user under which it is
 operating to perhaps identify ssh keys or other local resources it
 needs to operate.  You might be able to cover this with command line
 options (e.g., plink supports -i to specify a key file to use), but
 you'll also need to ensure that the file you are referencing is
 readable by the LocalSystem account.

 One of the other responders had a very good point about locating plink
 in the first place too.  Services run beneath an environment that is
 inherited from the service control manager process, and won't include
 various settings that are applied to your user when logged in,
 especially things like local path changes, and working directories.
 Should you change the system path (via the environment settings),
 you'll need to reboot for the service control manager to notice - I
 don't think you can restart it without a reboot.

 So it's generally safer to be very clear, and absolute when possible,
 in a service for paths to external resources.

 The prior advice of running the service as an identified user (e.g.,
 with local credentials) is still good as it does remove most of these
 issues since if you can run the script manually under that user you
 know it'll work under service.  But it's not a hard requirement.

 If your script is dying such that a top level exception is being
 raised you should be able to find it in the application event log.  So
 that might give further information on what about the different
 environment is problematic.

 You can also use the win32traceutil module to help with grabbing debug
 output on the fly.  Import the module in your service, which will
 implicitly redirect stdout/stderr to a trace buffer.  Run the same
 win32traceutil module from the command line in another window.  Then
 start the service.  Any stdout/stderr will be reflected in the other
 window.  Can't catch everything (suppressed exceptions, or I/O that
 doesn't flow through the script's stdout/stderr), but again might help
 point in the right direction.

 -- David

Great suggestions once again - I did verify that it was at least
running the plink.exe binary when under LocalSystem by having the
service run plink.exe  C:\plinkoutput.txt - this worked fine.  And,
as I mentioned, it's now working just fine when running under a
regular admin account.  So, I think that's going to be my solution to
avoid any further issues.  My best guess at this point (as you
mentioned), is that plink.exe is doing _something_ network-related
that LocalSystem doesn't have the privileges to do - what exactly it
is, I have no idea.  I may play around with it some more later, but
running the service under an admin account should be a perfectly
acceptable solution.

Also, I will be writing other Python apps that the service will be
executing - so it goes without saying that I'll be including a log to
file option :)  Thanks again for all your guys' help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-09 Thread T
On Feb 8, 2:25 pm, David Bolen db3l@gmail.com wrote:
 T misceveryth...@gmail.com writes:
  I have a script, which runs as a Windows service under the LocalSystem
  account, that I wish to have execute some commands.  Specifically, the
  program will call plink.exe to create a reverse SSH tunnel.  Right now
  I'm using subprocess.Popen to do so.  When I run it interactively via
  an admin account, all is well.  However, when I'm running it via
  service, no luck.  I'm assuming this is to do with the fact that it's
  trying to run under the LocalSystem account, which is failing.  What
  would be the best way around this?  Thanks!

 The LocalSystem account is not, if I recall correctly, permitted to
 access the network.

 You'll have to install the service to run under some other account that
 has appropriate access to the network.

 -- David

The more testing I do, I think you may be right..I was able to get it
to work under a local admin account, and it worked under debug mode
(which would also have been running as this user).  I'm a bit
surprised though - I was under the assumption that LocalSystem had
rights to access the network?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-09 Thread David Bolen
T misceveryth...@gmail.com writes:

 I have a script, which runs as a Windows service under the LocalSystem
 account, that I wish to have execute some commands.  Specifically, the
 program will call plink.exe to create a reverse SSH tunnel.  Right now
 I'm using subprocess.Popen to do so.  When I run it interactively via
 an admin account, all is well.  However, when I'm running it via
 service, no luck.  I'm assuming this is to do with the fact that it's
 trying to run under the LocalSystem account, which is failing.  What
 would be the best way around this?  Thanks!

The LocalSystem account is not, if I recall correctly, permitted to
access the network.

You'll have to install the service to run under some other account that
has appropriate access to the network.

-- David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-09 Thread Sean DiZazzo
On Feb 9, 6:52 am, T misceveryth...@gmail.com wrote:
 On Feb 8, 2:25 pm, David Bolen db3l@gmail.com wrote:



  T misceveryth...@gmail.com writes:
   I have a script, which runs as a Windows service under the LocalSystem
   account, that I wish to have execute some commands.  Specifically, the
   program will call plink.exe to create a reverse SSH tunnel.  Right now
   I'm using subprocess.Popen to do so.  When I run it interactively via
   an admin account, all is well.  However, when I'm running it via
   service, no luck.  I'm assuming this is to do with the fact that it's
   trying to run under the LocalSystem account, which is failing.  What
   would be the best way around this?  Thanks!

  The LocalSystem account is not, if I recall correctly, permitted to
  access the network.

  You'll have to install the service to run under some other account that
  has appropriate access to the network.

  -- David

 The more testing I do, I think you may be right..I was able to get it
 to work under a local admin account, and it worked under debug mode
 (which would also have been running as this user).  I'm a bit
 surprised though - I was under the assumption that LocalSystem had
 rights to access the network?

You really need a way to see the error you are getting.  If you can't
get it to show you the error in the shell, set up some logging to a
file, and find the error that way.  I think the user can access the
network just fine, but that maybe plink.exe is not in his path or some
such thing.

Find the error!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-09 Thread David Bolen
T misceveryth...@gmail.com writes:

 The more testing I do, I think you may be right..I was able to get it
 to work under a local admin account, and it worked under debug mode
 (which would also have been running as this user).  I'm a bit
 surprised though - I was under the assumption that LocalSystem had
 rights to access the network?

Not from my past experience - the system account (LocalSystem for
services) can be surprising, in that it's pretty much unlimited access
to all local resources, but severely limited in a handful of cases,
one of which is any attempt to access the network.  I can't recall for
sure if it's an absolute block, or if in some cases you can configure
around it (e.g., it might use a null session for remote shares which
can be enabled through the registry on the target machine).  I've
basically stuck LocalSystem = no network in my head from past
experience.

So you can either install your service to run under your existing
account, or create an account specifically for running your service,
granting that account just the rights it needs.

-- David






-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-09 Thread David Bolen
David Bolen db3l@gmail.com writes:

 Not from my past experience - the system account (LocalSystem for
 services) can be surprising, in that it's pretty much unlimited access
 to all local resources, but severely limited in a handful of cases,
 one of which is any attempt to access the network.  I can't recall for
 sure if it's an absolute block, or if in some cases you can configure
 around it (e.g., it might use a null session for remote shares which
 can be enabled through the registry on the target machine).  I've
 basically stuck LocalSystem = no network in my head from past
 experience.

Given it's been a few years, I decided to try some tests, and the
above is too simplistic.

The LocalSystem account runs without any local Windows credentials
(e.g., not like a logged in user), which has several consequences.
One is that you can't access any network resources that require such
credentials (like shares).  However, there's no sort of firewall
filtering or anything, so plain old TCP/IP connections are fine.
Unless, of course, the client being used also has other needs for
local Windows credentials, independent or as a pre-requisite to the
network operations.

So backing up a bit, the TCP/IP connection that plink is making is not
inherently disabled by running under LocalSystem, but it's certainly
possible that plink is trying to identify the user under which it is
operating to perhaps identify ssh keys or other local resources it
needs to operate.  You might be able to cover this with command line
options (e.g., plink supports -i to specify a key file to use), but
you'll also need to ensure that the file you are referencing is
readable by the LocalSystem account.

One of the other responders had a very good point about locating plink
in the first place too.  Services run beneath an environment that is
inherited from the service control manager process, and won't include
various settings that are applied to your user when logged in,
especially things like local path changes, and working directories.
Should you change the system path (via the environment settings),
you'll need to reboot for the service control manager to notice - I
don't think you can restart it without a reboot.

So it's generally safer to be very clear, and absolute when possible,
in a service for paths to external resources.

The prior advice of running the service as an identified user (e.g.,
with local credentials) is still good as it does remove most of these
issues since if you can run the script manually under that user you
know it'll work under service.  But it's not a hard requirement.

If your script is dying such that a top level exception is being
raised you should be able to find it in the application event log.  So
that might give further information on what about the different
environment is problematic.

You can also use the win32traceutil module to help with grabbing debug
output on the fly.  Import the module in your service, which will
implicitly redirect stdout/stderr to a trace buffer.  Run the same
win32traceutil module from the command line in another window.  Then
start the service.  Any stdout/stderr will be reflected in the other
window.  Can't catch everything (suppressed exceptions, or I/O that
doesn't flow through the script's stdout/stderr), but again might help
point in the right direction.

-- David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-08 Thread T
Thanks for the suggestions -  I think my next step is to try running
it under an admin user account, as you guys both mentioned.  Alf -
you're absolutely right, Microsoft has srvany.exe, which allows you to
run any EXE as a Windows service.  I've done this in the past, but
it's more of a hack..so this go around (since I will be distributing
this program), I wanted to go the more professional route..which,
unfortunately, involves learning the scum. :)  I  posted this to
comp.os.ms-windows.programmer.win32, so we'll see if what the Win32
programmers have to say as well.  Thanks again!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-08 Thread Sean DiZazzo


 It's working fine when I run it via servicename debug - that's how
 I was testing before.  It's when I start the service that it fails -
 and you can see that, when you run it with debug, plink.exe runs under
 my username.  When I run it as a service, it runs under System...

You can have the service run as any user under the service
properties.  Perhaps set the service to run under your username?

There may be some environment variables set in your session that
aren't in the one its running as.  So maybe check there as well.

Off to drink beer.  Good luck.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-08 Thread T
On Feb 8, 1:28 am, Sean DiZazzo half.ital...@gmail.com wrote:
 On Feb 7, 4:57 pm, T misceveryth...@gmail.com wrote:

  Thanks for the suggestions -  I think my next step is to try running
  it under an admin user account, as you guys both mentioned.  Alf -
  you're absolutely right, Microsoft has srvany.exe, which allows you to
  run any EXE as a Windows service.  I've done this in the past, but
  it's more of a hack..so this go around (since I will be distributing
  this program), I wanted to go the more professional route..which,
  unfortunately, involves learning the scum. :)  I  posted this to
  comp.os.ms-windows.programmer.win32, so we'll see if what the Win32
  programmers have to say as well.  Thanks again!

 I use windows services and they are very reliable.  I would say though
 that relying on plink.exe is much less reliable than either python or
 the service that it is running under.

 Why not take a look at paramiko as the ssh client library?  I think it
 runs under windows.  Also perhaps Twisted has something.  Either way
 would be light years ahead of using subprocess with plink.

 Just my thoughts.

 ~Sean

I totally agree that it would be much more reliable to use a Python
library for SSH - however, the program will need to execute other
external binaries as well.  So my goal at this point is to track down
_why_ it's failing when running as a service.  The actual command is
as follows:

C:\plink.exe -R :127.0.0.1:2020 -batch -i C:\keyfile.ppk
u...@10.10.10.1

I tried having subprocess.Popen run plink.exe by itself and piping
output to file, and this worked - so I know it's at least executing
plink.exe.  Sorry, I realize this isn't truly just a Python-related
question, but any help would be greatly appreciated!  So far no help
at comp.os.ms-windows.programmer.win32..
-- 
http://mail.python.org/mailman/listinfo/python-list


Executing Commands From Windows Service

2010-02-07 Thread T
I have a script, which runs as a Windows service under the LocalSystem
account, that I wish to have execute some commands.  Specifically, the
program will call plink.exe to create a reverse SSH tunnel.  Right now
I'm using subprocess.Popen to do so.  When I run it interactively via
an admin account, all is well.  However, when I'm running it via
service, no luck.  I'm assuming this is to do with the fact that it's
trying to run under the LocalSystem account, which is failing.  What
would be the best way around this?  Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-07 Thread Stephen Hansen
On Sun, Feb 7, 2010 at 11:02 AM, T misceveryth...@gmail.com wrote:

 I have a script, which runs as a Windows service under the LocalSystem
 account, that I wish to have execute some commands.  Specifically, the
 program will call plink.exe to create a reverse SSH tunnel.  Right now
 I'm using subprocess.Popen to do so.  When I run it interactively via
 an admin account, all is well.  However, when I'm running it via
 service, no luck.  I'm assuming this is to do with the fact that it's
 trying to run under the LocalSystem account, which is failing.  What
 would be the best way around this?  Thanks!


I don't know what your specific issue is, but here's some tips for running
Python as a service on windows which are not always immediately obvious and
can cause failures:

- The search path is screwy: if you are importing a module that happens to
be the same name as a dll in system32 (even if this isn't at all a python
dll), it can get confused.
- There is *no* sys.stdout! This is a big one. If any piece of code you're
using ever does 'print', the whole thing can crash hard. I replace
sys.stdout and sys.stderr with a fake file-like object that catches errors
in attempting to .write to the real one and ignores them.

If neither of those two are a problem for you, you need to define no luck
before anyone will be able to help you. Are there errors in the event
viewer? Are you getting an exception that's killing out your service
(capture and write to a file with the logging module)? Or is the Popen call
being run and returning but just not doing anything (in which case, try
capturing output from the command and see if it indicates an error message
from plink.exe). Etc.

--S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-07 Thread Sean DiZazzo
On Feb 7, 11:02 am, T misceveryth...@gmail.com wrote:
 I have a script, which runs as a Windows service under the LocalSystem
 account, that I wish to have execute some commands.  Specifically, the
 program will call plink.exe to create a reverse SSH tunnel.  Right now
 I'm using subprocess.Popen to do so.  When I run it interactively via
 an admin account, all is well.  However, when I'm running it via
 service, no luck.  I'm assuming this is to do with the fact that it's
 trying to run under the LocalSystem account, which is failing.  What
 would be the best way around this?  Thanks!

Try running/debugging your service from the commandline as
servicename debug  That should lead you to the error.

Otherwise, we need to see a traceback and some code to be better able
to help.

~Sean

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-07 Thread T
On Feb 7, 4:43 pm, Sean DiZazzo half.ital...@gmail.com wrote:
 On Feb 7, 11:02 am, T misceveryth...@gmail.com wrote:

  I have a script, which runs as a Windows service under the LocalSystem
  account, that I wish to have execute some commands.  Specifically, the
  program will call plink.exe to create a reverse SSH tunnel.  Right now
  I'm using subprocess.Popen to do so.  When I run it interactively via
  an admin account, all is well.  However, when I'm running it via
  service, no luck.  I'm assuming this is to do with the fact that it's
  trying to run under the LocalSystem account, which is failing.  What
  would be the best way around this?  Thanks!

 Try running/debugging your service from the commandline as
 servicename debug  That should lead you to the error.

 Otherwise, we need to see a traceback and some code to be better able
 to help.

 ~Sean

It's working fine when I run it via servicename debug - that's how
I was testing before.  It's when I start the service that it fails -
and you can see that, when you run it with debug, plink.exe runs under
my username.  When I run it as a service, it runs under System...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-07 Thread Alf P. Steinbach

* T:

On Feb 7, 4:43 pm, Sean DiZazzo half.ital...@gmail.com wrote:

On Feb 7, 11:02 am, T misceveryth...@gmail.com wrote:


I have a script, which runs as a Windows service under the LocalSystem
account, that I wish to have execute some commands.  Specifically, the
program will call plink.exe to create a reverse SSH tunnel.  Right now
I'm using subprocess.Popen to do so.  When I run it interactively via
an admin account, all is well.  However, when I'm running it via
service, no luck.  I'm assuming this is to do with the fact that it's
trying to run under the LocalSystem account, which is failing.  What
would be the best way around this?  Thanks!

Try running/debugging your service from the commandline as
servicename debug  That should lead you to the error.

Otherwise, we need to see a traceback and some code to be better able
to help.

~Sean


It's working fine when I run it via servicename debug - that's how
I was testing before.  It's when I start the service that it fails -
and you can see that, when you run it with debug, plink.exe runs under
my username.  When I run it as a service, it runs under System...


This sounds like a Windows programming problem, not anything related to Python 
per se.


Windows services are generally limited in what they can do, such as interaction 
with the  user, and I guess that spills over to network access.


Also, services need to interact with the service control manager, the scum as 
it's known. Well, all right, that's just what my coworkers and I called it once. 
But essentially, it's an even-driven execution model, which means that it might 
not work to use just any program, such as [python.exe], directly as a service.


The Windows Resource Kit used to have a facility for running ordinary programs 
as services. I'm not sure what it did at the technical level, but it worked. Or 
it appeared to work.


You might also find it useful to look up the documentation on services that 
interact with the user. In the old times that was mostly a matter of configuring 
which account the service ran under. But I think it all got more complicated 
with Microsoft's introduction of Terminal services (generally, most of the 
complication in modern Windows is due to the shift in focus about 1995, ditching 
the personal computer user market in favor of the enterprise and MIS market).


Cross-posted to [comp.os.ms-windows.programmer.win32], follow-ups set to that 
group  --  that means, unless overridden you won't see follow-ups in [c.l.p].


I think that group may give more informative and helpful responses.


Cheers  hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: Executing Commands From Windows Service

2010-02-07 Thread Sean DiZazzo
On Feb 7, 4:57 pm, T misceveryth...@gmail.com wrote:
 Thanks for the suggestions -  I think my next step is to try running
 it under an admin user account, as you guys both mentioned.  Alf -
 you're absolutely right, Microsoft has srvany.exe, which allows you to
 run any EXE as a Windows service.  I've done this in the past, but
 it's more of a hack..so this go around (since I will be distributing
 this program), I wanted to go the more professional route..which,
 unfortunately, involves learning the scum. :)  I  posted this to
 comp.os.ms-windows.programmer.win32, so we'll see if what the Win32
 programmers have to say as well.  Thanks again!

I use windows services and they are very reliable.  I would say though
that relying on plink.exe is much less reliable than either python or
the service that it is running under.

Why not take a look at paramiko as the ssh client library?  I think it
runs under windows.  Also perhaps Twisted has something.  Either way
would be light years ahead of using subprocess with plink.

Just my thoughts.

~Sean
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: capture stdout and stderror from within a Windows Service?

2009-05-15 Thread Chris Curvey
On May 14, 11:57 am, Chris Curvey ccur...@gmail.com wrote:
 I'm trying to get this invocation right, and it is escaping me.  How
 can I capture the stdout and stderr if I launch a subprocess using 
 subprocess.check_call()?  The twist here is that the call is running
 from within a Windows service.

 I've tried:

 check_call(mycmd.exe, stdout=subprocess.PIPE)  [raises an exception
 An integer is required]

 check_call(mycmd.exe, stdout=file(c:\\temp\\foobar.txt, w))
 [raises an exception An integer is required]

Ahhh, Blake put me on the right track.  If you want any of the
streams, you have to supply values for all of them, like so:

p = subprocess.Popen(step, shell=True
  stdout=subprocess.PIPE,
  stdin=subprocess.PIPE,
  stderr=subprocess.PIPE)

(stdout, stderr) = p.communicate()

and, incidentally, it appears that you have to use UNC paths in your
Popen call -- drive letters won't work.

so dir \\foobar\myshare\mydir will work, but dir j:\mydir will
not.

Many thanks for all your assistance.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: capture stdout and stderror from within a Windows Service?

2009-05-15 Thread Tim Golden

Chris Curvey wrote:

Ahhh, Blake put me on the right track.  If you want any of the
streams, you have to supply values for all of them, like so:

p = subprocess.Popen(step, shell=True
  stdout=subprocess.PIPE,
  stdin=subprocess.PIPE,
  stderr=subprocess.PIPE)

(stdout, stderr) = p.communicate()

and, incidentally, it appears that you have to use UNC paths in your
Popen call -- drive letters won't work.



This is because you're running in a service. Drive letters
aren't system wide: they're per-user. The service won't
know about any drive letters you or anyone else happens
to have mapped.

TJG
--
http://mail.python.org/mailman/listinfo/python-list


capture stdout and stderror from within a Windows Service?

2009-05-14 Thread Chris Curvey
I'm trying to get this invocation right, and it is escaping me.  How
can I capture the stdout and stderr if I launch a subprocess using
subprocess.check_call()?  The twist here is that the call is running
from within a Windows service.

I've tried:

check_call(mycmd.exe, stdout=subprocess.PIPE)  [raises an exception
An integer is required]

check_call(mycmd.exe, stdout=file(c:\\temp\\foobar.txt, w))
[raises an exception An integer is required]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: capture stdout and stderror from within a Windows Service?

2009-05-14 Thread Chris Rebert
On Thu, May 14, 2009 at 8:57 AM, Chris Curvey ccur...@gmail.com wrote:
 I'm trying to get this invocation right, and it is escaping me.  How
 can I capture the stdout and stderr if I launch a subprocess using
 subprocess.check_call()?  The twist here is that the call is running
 from within a Windows service.

 I've tried:

 check_call(mycmd.exe, stdout=subprocess.PIPE)  [raises an exception
 An integer is required]

 check_call(mycmd.exe, stdout=file(c:\\temp\\foobar.txt, w))
 [raises an exception An integer is required]

Providing the full exception Tracebacks would be highly recommended.

Cheers,
Chris
-- 
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: capture stdout and stderror from within a Windows Service?

2009-05-14 Thread Grant Edwards
On 2009-05-14, Chris Curvey ccur...@gmail.com wrote:
 I'm trying to get this invocation right, and it is escaping me.  How
 can I capture the stdout and stderr if I launch a subprocess using
 subprocess.check_call()?  The twist here is that the call is running
 from within a Windows service.

 I've tried:

 check_call(mycmd.exe, stdout=subprocess.PIPE)  [raises an exception
 An integer is required]

 check_call(mycmd.exe, stdout=file(c:\\temp\\foobar.txt, w))
 [raises an exception An integer is required]

An educated guess...

By default, subprocess will use the existing stdin, stdout, and
stderr filedescriptors for the child process. Since services
presumably don't have valid file descriptors for stdin, stdout,
and stderr, you probably have to tell subprocess to use pipes
for all three.  Otherwise, it will default to using the invalid
or nonexistant file descriptors of the parent.

[If you reply, I proably won't see it.  All posts from google
groups are plonked by my newsreader configuration.  It was
somewhat of a fluke that I came across your posting.]

-- 
Grant Edwards   grante Yow! On the road, ZIPPY
  at   is a pinhead without a
   visi.compurpose, but never without
   a POINT.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: capture stdout and stderror from within a Windows Service?

2009-05-14 Thread norseman

Chris Curvey wrote:

I'm trying to get this invocation right, and it is escaping me.  How
can I capture the stdout and stderr if I launch a subprocess using
subprocess.check_call()?  The twist here is that the call is running
from within a Windows service.

I've tried:

check_call(mycmd.exe, stdout=subprocess.PIPE)  [raises an exception
An integer is required]


mycmd.exe isn't open (running). the mycmd.exe is supposed to be a fn.
How did you start it?



check_call(mycmd.exe, stdout=file(c:\\temp\\foobar.txt, w))
[raises an exception An integer is required]

==
I think you need to run the .exe from your .py using the subprocess 
module's commands and hook in at that time to stdin, stdout, 

get the fn and use check_call() to see if .exe has something to say.

Check subprocess's help/man and so forth.

I know that if you start a program via os.Popen2's popen3 things work as 
expected.  How you would redirect I/O in an arbitrary already running 
program in Windows is a good question.



Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: capture stdout and stderror from within a Windows Service?

2009-05-14 Thread David Lyon
On Thu, 14 May 2009 11:16:51 -0500, Grant Edwards inva...@invalid wrote:
 On 2009-05-14, Chris Curvey ccur...@gmail.com wrote:
 I'm trying to get this invocation right, and it is escaping me.  How
 can I capture the stdout and stderr if I launch a subprocess using
 subprocess.check_call()?  The twist here is that the call is running
 from within a Windows service.

 I've tried:

 check_call(mycmd.exe, stdout=subprocess.PIPE)  [raises an exception
 An integer is required]

 check_call(mycmd.exe, stdout=file(c:\\temp\\foobar.txt, w))
 [raises an exception An integer is required]

In the past, windows services have never been allowed to make any output
to the console or the GDI or get any user input. Rules said they could 
send stuff to syslog etc.

All writing can go to logfiles and so forth...

I've never heard of that being allowable

David

-- 
http://mail.python.org/mailman/listinfo/python-list


[issue5162] multiprocessing cannot spawn child from a Windows service

2009-03-29 Thread Jesse Noller

Changes by Jesse Noller jnol...@gmail.com:


--
priority:  - normal

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5162] multiprocessing cannot spawn child from a Windows service

2009-03-06 Thread Daniel Diniz

Changes by Daniel Diniz aja...@gmail.com:


--
assignee:  - jnoller
keywords: +patch
stage:  - test needed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5162
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Using multiprocessing from a Windows service

2009-02-06 Thread Mark Hammond

On 6/02/2009 4:21 PM, Volodymyr Orlenko wrote:

In the patch I submitted, I simply check if the name of the supposed
module ends with .exe. It works fine for my case, but maybe this is
too general. Is there a chance that a Python module would end in .exe?


IIRC, py2exe may create executables where sys.argv[0] is the executable 
itself.  Maybe if we consider and handle both these cases a patch to mp 
might be looked upon in a better light...


Cheers,

Mark
--
http://mail.python.org/mailman/listinfo/python-list


Using multiprocessing from a Windows service

2009-02-05 Thread Volodya
Hi all,

I think I've found a small bug with multiprocessing package on
Windows. If you try to start a multiprocessing.Process from a Python-
based Windows service, the child process will fail to run. When
running the parent process as a regular Python program, everything
works as expected.

I've tracked the problem down to how main_path is prepared in
multiprocessing.forking.get_preparation_data() (lines 370-377):

def get_preparation_data(name):
[...skipped a few lines...]
if not WINEXE:
main_path = getattr(sys.modules['__main__'], '__file__', None)
if not main_path and sys.argv[0] not in ('', '-c'):
main_path = sys.argv[0]
if main_path is not None:
if not os.path.isabs(main_path) and \
  process.ORIGINAL_DIR is not
None:
main_path = os.path.join(process.ORIGINAL_DIR,
main_path)
d['main_path'] = os.path.normpath(main_path)
return d

When the program is running as a Windows service, but is not packaged
into a single executable, main_path will become the path to the
service executable (typically, pythonservice.exe). When this data
makes it to the child process, the prepare() function will treat
main_path as a path to a python module, and will try to import it.
This causes it to fail.

My quick-and-dirty solution was to check in get_preparation_data() if
main_path ends with '.exe', and if it does, to not pass it at all.
This solves the problem in my case, but perhaps there's a better way
to fix this? Here is my version of get_preparation_data():

def get_preparation_data(name):
'''
Return info about parent needed by child to unpickle process
object
'''
from .util import _logger, _log_to_stderr

d = dict(
name=name,
sys_path=sys.path,
sys_argv=sys.argv,
log_to_stderr=_log_to_stderr,
orig_dir=process.ORIGINAL_DIR,
authkey=process.current_process().authkey,
)

if _logger is not None:
d['log_level'] = _logger.getEffectiveLevel()

if not WINEXE:
main_path = getattr(sys.modules['__main__'], '__file__', None)
if not main_path and sys.argv[0] not in ('', '-c'):
main_path = sys.argv[0]
if main_path is not None:
if not os.path.isabs(main_path) and \
  process.ORIGINAL_DIR is not
None:
main_path = os.path.join(process.ORIGINAL_DIR,
main_path)
if not main_path.endswith('.exe'):
d['main_path'] = os.path.normpath(main_path)

return d


--
http://mail.python.org/mailman/listinfo/python-list


Re: Using multiprocessing from a Windows service

2009-02-05 Thread Mark Hammond

On 6/02/2009 11:37 AM, Volodya wrote:

Hi all,

I think I've found a small bug with multiprocessing package on
Windows.


I'd actually argue its a bug in pythonservice.exe - it should set 
sys.argv[] to resemble a normal python process with argv[0] being the 
script.  I'll fix it...


Cheers,

Mark
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using multiprocessing from a Windows service

2009-02-05 Thread Mark Hammond

On 6/02/2009 2:50 PM, Mark Hammond wrote:

On 6/02/2009 11:37 AM, Volodya wrote:

Hi all,

I think I've found a small bug with multiprocessing package on
Windows.


I'd actually argue its a bug in pythonservice.exe - it should set
sys.argv[] to resemble a normal python process with argv[0] being the
script. I'll fix it...


Actually it appears I spoke too soon:

* A bug in pywin32 exists such that when you use 'debug' on a service, 
the argv reflected the full argv of the application, including the 
'-debug' portion of the command-line.  However, even if that is fixed, 
the next argument is actually the name of the service (as declared in 
the .py file for the service), not the .py module itself.  Thus, I could 
make argv a little more sane in this case, but still the initial problem 
would remain as argv[0] would still not be a .py file.


* When the service is started by windows itself, there are usually zero 
additional command-line arguments.  If there *are* arguments, they are 
likely to be the string the user entered via control panel as a special 
case (Windows doesn't actually remember service args - they are used 
once and discarded).  It is important we continue to expose whatever 
argv we actually got from Windows to the service code.


So unfortunately I don't think I can change pythonservice to resolve the 
issue you reported.


Cheers,

Mark
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using multiprocessing from a Windows service

2009-02-05 Thread Volodymyr Orlenko



On 05/02/2009 8:26 PM, Mark Hammond wrote:

On 6/02/2009 2:50 PM, Mark Hammond wrote:

On 6/02/2009 11:37 AM, Volodya wrote:

Hi all,

I think I've found a small bug with multiprocessing package on
Windows.


I'd actually argue its a bug in pythonservice.exe - it should set
sys.argv[] to resemble a normal python process with argv[0] being the
script. I'll fix it...


Actually it appears I spoke too soon:

* A bug in pywin32 exists such that when you use 'debug' on a service, 
the argv reflected the full argv of the application, including the 
'-debug' portion of the command-line.  However, even if that is fixed, 
the next argument is actually the name of the service (as declared in 
the .py file for the service), not the .py module itself.  Thus, I 
could make argv a little more sane in this case, but still the initial 
problem would remain as argv[0] would still not be a .py file.


* When the service is started by windows itself, there are usually 
zero additional command-line arguments.  If there *are* arguments, 
they are likely to be the string the user entered via control panel as 
a special case (Windows doesn't actually remember service args - they 
are used once and discarded).  It is important we continue to expose 
whatever argv we actually got from Windows to the service code.


So unfortunately I don't think I can change pythonservice to resolve 
the issue you reported.



Thanks Mark, this makes perfect sense.

In the patch I submitted, I simply check if the name of the supposed 
module ends with .exe. It works fine for my case, but maybe this is 
too general. Is there a chance that a Python module would end in .exe? 
If so, maybe we should check specifically for pythonservice.exe. But 
then, if someone renames the executable (as I did, because I wanted to 
see meaningful service names in the process list), the patch will not 
work. Maybe there's another way to fix the forking module?

--
http://mail.python.org/mailman/listinfo/python-list


Re: Using multiprocessing from a Windows service

2009-02-05 Thread James Mills
On Fri, Feb 6, 2009 at 3:21 PM, Volodymyr Orlenko orle...@gmail.com wrote:
 In the patch I submitted, I simply check if the name of the supposed module
 ends with .exe. It works fine for my case, but maybe this is too general.
 Is there a chance that a Python module would end in .exe? If so, maybe we
 should check specifically for pythonservice.exe. But then, if someone
 renames the executable (as I did, because I wanted to see meaningful service
 names in the process list), the patch will not work. Maybe there's another
 way to fix the forking module?

I believe the best way to fix this is to fix the underlying
issue that Mark has pointed out (monkey-patching mp won't do).

--JamesMills
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >