Skip to content

Instantly share code, notes, and snippets.

@openfly
Created December 20, 2016 22:05
Show Gist options
  • Save openfly/6f9dc216f375bed6720141cbc6552544 to your computer and use it in GitHub Desktop.
Save openfly/6f9dc216f375bed6720141cbc6552544 to your computer and use it in GitHub Desktop.
testing multiprocessing
import listener
import requests
import multiprocessing
from multiprocessing import Pool
import sys
# from multiprocessing.dummy import Pool as ThreadPool
def test_print():
print "test_print called."
def poll_api(lister):
p = multiprocessing.current_process()
print p.name
print p.pid
while(True):
response = requests.get('http://localhost:8844/date')
print response.text
lister.onChange.fire()
break
# sys.stdout.flush()
return 0
lister = listener.Listener()
# lister.onChange += test_print
bg = multiprocessing.Process(name='daemon', target=poll_api(lister))
bg.daemon = True
bg.start()
print 'testing beyond thread'
# add a listener to the event
lister.onChange += test_print
#lister.onChange.fire()
# remove listener from the event
lister.onChange -= test_print
# fire event
lister.onChange.fire()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment