Skip to content

Instantly share code, notes, and snippets.

@sujayy1983
Created January 14, 2015 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sujayy1983/dc0a18a90362826c666a to your computer and use it in GitHub Desktop.
Save sujayy1983/dc0a18a90362826c666a to your computer and use it in GitHub Desktop.
Multiprocessing simplest example.
"""
@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