multiprocessing help
I'm looking for some help with multiprocessing. Essentially what I'm trying to do is the following: 1. create a main process that gets daemonized 2. spawn two subprocess that live for the life of the daemon 3. each subprocess creates children that do heavy work and exit when the work is done I am not having issues with creating the processes but I can't get them to die. Sometimes it works and they all die and sometimes they don't. Obviously I do not understand the multiprocessing documentation so I'm hoping that somebody can point out what I'm doing wrong. I also understand that my code might be strict adherence to PEP8 and there might be a number of flaws with the code; all of which would be helpful to know, but I'm particularly looking for help with getting what I'm trying to do to work. I'm starting to lose my mind.. I just want to say all processes that spawned from here $@%@$% DIE. Thanks in advance for anybody that has some spare time to point me in the right direction. I am grateful. Thanks. Very Respectfully, Stephen Bunn scb...@sbunn.org sqlimport.py Description: Binary data daemon.py Description: Binary data maindaemon.py Description: Binary data -- http://mail.python.org/mailman/listinfo/python-list
running multiple scripts -- which way is more elegant?
List, First I'm very new to Python. I usually do this kind of thing with shell scripts, however, I'm trying to move to using python primarily so I can learn the language. I'm attempting to write a script that will check a server for various configuration settings and report and/or change based on those findings. I know there are other tools that can do this, but for various reasons I must script this. I have come up with two ways to accomplish what I'm trying to do and I'm looking for the more elegant solution -- or if there is another solution that I have not thought of. Any input would be greatly appreciated and thanks for your time. method 1: = [master script] def execute_script(cscript): process = subprocess.Popen(cscript, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output_data = process.communicate() if process.returncode == 0: return "OK" elif process.returncode == 90: return "DEFER" elif process.returncode == 80: return "UPDATED" else: return "ERROR" if __name__ == '__main__': # Find all configuration scripts print "Searching for config scripts" cscripts = [] for config_script in os.listdir(BASE_DIR + "/config.d"): cscripts.append(BASE_DIR + '/config.d/' + config_script) print "Found %d configuration scripts" % (len(cscripts)) # Loop through scripts and execute for config_script in cscripts: action_title = "Checking %s" % (config_script[len(BASE_DIR + '/config.d/'):]) print "%-75.75s [ %s ]" % (action_title, execute_script(config_script)) [config script template] #!/usr/bin/env python def check(): # do some checking return results return check() method 2: [master script] if __name__ == '__main__': # Find all configuration scripts print "Searching for config scripts" cscripts = [] for config_script in os.listdir(BASE_DIR + "/config.d"): cscripts.append(BASE_DIR + '/config.d/' + config_script) print "Found %d configuration scripts" % (len(cscripts)) # Loop through scripts and execute for config_script in cscripts: import config_script action_title = "Checking %s" % (config_script[len(BASE_DIR + '/config.d/'):]) print "%-75.75s [ %s ]" % (action_title, config_script.check()) [config script template] #!/usr/bin/env python def check(): # do some stuff return result # return str OK, DEFER, UPDATED or ERROR -- http://mail.python.org/mailman/listinfo/python-list
Re: running multiple scripts -- which way is more elegant?
On Mon, Jun 20, 2011 at 1:26 PM, Chris Angelico wrote: > > I'd be inclined toward the second solution if I'm writing all the code > > myself > On Mon, Jun 20, 2011 at 3:21 PM, Florencio Cano wrote: > I'm with Chris, if the config_scripts are going to be implemented in > Python always, the second solution is better for me as the operative > system is less involved. > Thanks for the replies. I would like to use the second method because I plan to implement everything in python. Unfortunately I have not been able to work out how to get the imports to work. import config_script obviously doesn't work and __import__(config_script) works from the python interpreter but fails in the script (ImportError: Import by filename is not supported.) -- http://mail.python.org/mailman/listinfo/python-list
Re: running multiple scripts -- which way is more elegant?
On Mon, Jun 20, 2011 at 11:19 PM, Florencio Cano wrote: > > import config_script obviously doesn't work and __import__(config_script) > > works from the python interpreter but fails in the script (ImportError: > > Import by filename is not supported.) > > You can use this: > > exec("import " + module_name) > > Thanks for the hint. I will give that a try. On Tue, Jun 21, 2011 at 2:48 AM, Terry Reedy wrote: > > The main problem of your second method is that you repeat the check > function in each script. That will be a problem if you ever want to modify > it. I might put is into a separate file and import into each script. > > repeating the check function in each script is what I think I want. The check function is what would scan the system and make sure that compliance is met. I'm slightly confused about how that would become an issue later and what you mean about importing each of them > > import config_script obviously doesn't work and >> __import__(config_script) works from the python interpreter but fails in >> the script (ImportError: Import by filename is not supported.) >> > > Look at builtin function __import__(filename). > Terry Jan Reedy I looked into __import__(filename) but that was not working for me, based upon the error in my previous message. I will give Florencio Cano's solution of using exec a try. If there are any other ideas out there I'm all ears :) Thanks everybody for the replies and guidance. -- http://mail.python.org/mailman/listinfo/python-list
Re: O'Reilly Python Certification
At Tue, 28 Dec 2010 20:07:29 + (UTC), J. Altman wrote: > > I have a general question. > > Does it seem odd that a certificate in Python, an Open Source > language; taught at O'Reilly, which offers an Open Source Programming > Certificate and is something like waist-deep in Open Source > publishing; is offered to the world at large but only (IIUC) if one > runs some version of Windows by MS? > > Based on what I am given to understand from my correspondence with > OST, it seems that I *must* install an instance of Windows to take the > certificate's courses. This is not true. You can take the course on any operating system that supports a RDP client. I am enrolled with in the python course and I use GNU/Linux. They even have instructions on their website on how to configure it. I would have preferred them to use a UNIX shell. I'm still waiting for somebody to come up with a course that teaches me a programming language, while teaching me a VCS and allows me to write code and submit to a repo with other students contributing. You want to bring people into F/OSS -- That is how you do it! The complaint that I do have with OST (at least the Python course) and the reason I have not completed (or even worked on the course in almost a year) it, is that its just plain boring. It's almost 2011! Give me some interactive flash, a video, something. Reading some pages of dry text just doesn't cut it for me. I can do that on my own. If I'm going to pay for a course I want a teacher that is going to teach me something. I can buy plenty of books and read them. The entire course is just plain dry text. I don't even remeber seeing an image diagram. On top of that the text is horribly ugly to look at. -- http://mail.python.org/mailman/listinfo/python-list
Re: O'Reilly Python Certification
At Tue, 28 Dec 2010 20:07:29 + (UTC), J. Altman wrote: > > I have a general question. > > Does it seem odd that a certificate in Python, an Open Source > language; taught at O'Reilly, which offers an Open Source Programming > Certificate and is something like waist-deep in Open Source > publishing; is offered to the world at large but only (IIUC) if one > runs some version of Windows by MS? > > Based on what I am given to understand from my correspondence with > OST, it seems that I *must* install an instance of Windows to take the > certificate's courses. This is not true. You can take the course on any operating system that supports a RDP client. I am enrolled with in the python course and I use GNU/Linux. They even have instructions on their website on how to configure it. I would have preferred them to use a UNIX shell. I'm still waiting for somebody to come up with a course that teaches me a programming language, while teaching me a VCS and allows me to write code and submit to a repo with other students contributing. You want to bring people into F/OSS -- That is how you do it! The complaint that I do have with OST (at least the Python course) and the reason I have not completed (or even worked on the course in almost a year) it, is that its just plain boring. It's almost 2011! Give me some interactive flash, a video, something. Reading some pages of dry text just doesn't cut it for me. I can do that on my own. If I'm going to pay for a course I want a teacher that is going to teach me something. I can buy plenty of books and read them. The entire course is just plain dry text. I don't even remeber seeing an image diagram. On top of that the text is horribly ugly to look at. -- http://mail.python.org/mailman/listinfo/python-list
Re: O'Reilly Python Certification
At Tue, 28 Dec 2010 20:07:29 + (UTC), J. Altman wrote: > > I have a general question. > > Does it seem odd that a certificate in Python, an Open Source > language; taught at O'Reilly, which offers an Open Source Programming > Certificate and is something like waist-deep in Open Source > publishing; is offered to the world at large but only (IIUC) if one > runs some version of Windows by MS? > > Based on what I am given to understand from my correspondence with > OST, it seems that I *must* install an instance of Windows to take the > certificate's courses. This is not true. You can take the course on any operating system that supports a RDP client. I am enrolled with in the python course and I use GNU/Linux. They even have instructions on their website on how to configure it. I would have preferred them to use a UNIX shell. I'm still waiting for somebody to come up with a course that teaches me a programming language, while teaching me a VCS and allows me to write code and submit to a repo with other students contributing. You want to bring people into F/OSS -- That is how you do it! The complaint that I do have with OST (at least the Python course) and the reason I have not completed (or even worked on the course in almost a year) it, is that its just plain boring. It's almost 2011! Give me some interactive flash, a video, something. Reading some pages of dry text just doesn't cut it for me. I can do that on my own. If I'm going to pay for a course I want a teacher that is going to teach me something. I can buy plenty of books and read them. The entire course is just plain dry text. I don't even remeber seeing an image diagram. On top of that the text is horribly ugly to look at. -- http://mail.python.org/mailman/listinfo/python-list