Skip to content

Commit

Permalink
Getting rid of multithreading to reconnect.
Browse files Browse the repository at this point in the history
  • Loading branch information
muammar committed Mar 25, 2016
1 parent 53d9be3 commit 78feb20
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions mkchromecast/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import time
import sys
from cast import *
import psutil
import os
import signal

"""
These functions are used to get up the streaming server.
Expand All @@ -29,32 +32,38 @@
name()
"""

def stream():
def launch_server():
webcast = ['./bin/node', './nodejs/node_modules/webcast-osx-audio/bin/webcast.js']
p = subprocess.Popen(webcast)
while p.poll() is None:
try:
time.sleep(0.5)
except KeyboardInterrupt:
print ("Ctrl-c was requested")
sys.exit(0)
else:
print ('Reconnecting streaming...')

relaunch(stream,recasting)

#thread = threading.Thread(target=launch_server)
#thread.daemon = True
#thread.start()
thread = multiprocessing.Process(target=launch_server)
thread.daemon = False
thread.start()
def streaming():
webcast = ['./bin/node', './nodejs/node_modules/webcast-osx-audio/bin/webcast.js']
p = subprocess.Popen(webcast)
while p.poll() is None:
try:
time.sleep(0.5)
except KeyboardInterrupt:
print ("Ctrl-c was requested")
sys.exit(0)
else:
print ('Reconnecting streaming...')
relaunch(stream,recasting,kill)

return

def relaunch(func,func1):
func()
class multi_proc(object):
def __init__(self):
self.proc = multiprocessing.Process(target=streaming)
self.proc.daemon = False

def start(self):
self.proc.start()

def kill():
pid=getpid()
os.kill(pid, signal.SIGTERM)

def relaunch(func1,func2,func3):
func1()
func2()
func3()

return

def recasting():
Expand All @@ -63,3 +72,7 @@ def recasting():
start.get_cc()
start.play_cast()
return

def stream():
st = multi_proc()
st.start()

0 comments on commit 78feb20

Please sign in to comment.