Created
January 14, 2015 19:36
-
-
Save sujayy1983/dc0a18a90362826c666a to your computer and use it in GitHub Desktop.
Multiprocessing simplest example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author Sujayyendhiren Ramarao | |
@Description Multiprocessing library example (Synchornization of shared variable) | |
""" | |
import nmap | |
import time | |
class Discover(object) : | |
def __init__(self): | |
print "Init Discover" | |
def discover_lan(self, lock, share): | |
while True: | |
lock.acquire() | |
share.value = 1 | |
lock.release() | |
print "Master Process: " + str(share.value) | |
class Cleanup(object) : | |
def __init__(self): | |
print "Init Cleanup" | |
def cleanup_handler(self,lock, share): | |
while True: | |
lock.acquire() | |
share.value = 3 | |
lock.release() | |
print "Cleanup Process: " + str(share.value) | |
#time.sleep(2) | |
class Logging(object): | |
def __init__(self): | |
print "Init Logging" | |
def logging_handler(self, lock, share ): | |
while True: | |
lock.acquire() | |
share.value = 2 | |
lock.release() | |
print "Logging Process: " + str(share.value) | |
def proc_handler( lock, action, num ): | |
print('Process action : ', action) | |
if action == 'discover': | |
newProcess = Discover() | |
newProcess.discover_lan( lock, num ) | |
elif action == 'cleanup': | |
newProcess = Cleanup() | |
newProcess.cleanup_handler( lock, num ) | |
elif action == 'logging': | |
newProcess = Logging() | |
newProcess.logging_handler( lock, num ) | |
else: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment