Ejemplo n.º 1
0
def runRTMP(addr=('0.0.0.0', 1935)): # create and run a flash server instance
    server = rtmp.FlashServer()
    server.apps = dict({'record': Record, 'call': Call}) # only support call and record applications  
    server.root = _www + _flvs
    server.start(*addr)
    if _debug: print time.asctime(), 'Flash server starts', addr
    try: multitask.run()
    except KeyboardInterrupt: thread.interrupt_main()
Ejemplo n.º 2
0
def runRTMP(addr=('0.0.0.0', 1935)): # create and run a flash server instance
    server = rtmp.FlashServer()
    server.apps = dict({'record': Record, 'call': Call}) # only support call and record applications  
    server.root = 'www/flvs/'
    server.start(*addr)
    if _debug: print time.asctime(), 'Flash server starts', addr
    try: multitask.run()
    except KeyboardInterrupt: thread.interrupt_main()
Ejemplo n.º 3
0
	def run(self):
		while True:
			try:
				agent = rtmp.FlashServer()
				agent.start()
				multitask.run()
			except:
				sys.exit(0)		
			time.sleep(2)
Ejemplo n.º 4
0
 def startRtmp(self):
     try:
         agent = FlashServer()
         agent.root = self.root
         agent.start(self.host, self.port)
         log.info(( time.asctime() , 'Flash Server Starts - %s:%d' % (self.host, self.port)))
         multitask.run()
     except KeyboardInterrupt:
         pass
     log.info((time.asctime() ,'Flash Server Stops'))
Ejemplo n.º 5
0
def runRTMP(addr=("0.0.0.0", 1935)):  # create and run a flash server instance
    server = rtmp.FlashServer()
    server.apps = dict({"record": Record, "call": Call})  # only support call and record applications
    server.root = _www + _flvs
    server.start(*addr)
    if _debug:
        print time.asctime(), "Flash server starts", addr
    try:
        multitask.run()
    except KeyboardInterrupt:
        thread.interrupt_main()
Ejemplo n.º 6
0
    def threadproc(arg):
        global sock1, pending, active

        def execute(s):
            if isinstance(s, p2p.ServerSocket):
                n = NetworkStub(Ks=crypto.generateRSA()[0],
                                cert=None,
                                model=model,
                                view=control.view)
                s.start(net=n)
                node = model.addNode(s.net.node.guid, s)
                s.net.node.index = node.index  # so that dht.Node has the index.
                active.append(s)
            else:
                if _debug: print s[0], s[1]
                result = yield s[0](**s[1])
                if not isinstance(result, list):
                    print result
                else:
                    if _debug: print result
                    values = map(lambda x: x[0], result)
                    print '\n'.join(values) if values else 'None'

        def waitonsock(sock):
            global pending
            try:
                while True:
                    yield multitask.recvfrom(sock, 10)
                    for s in pending:
                        multitask.add(execute(s))
                    pending[:] = []
            except StopIteration:
                raise
            except:
                print 'waitonsock', sys.exc_info(), traceback.print_exc()

        multitask.add(
            waitonsock(sock1))  # this will trigger multitask out of wait loop

        if _debug: print 'starting multitask.run()'
        if _trace: sys.settrace(traceit)
        try:
            multitask.run()
        except KeyboardInterrupt:
            interrupt_main()
        except:
            if _debug:
                print 'exception in multitask.run()'
                traceback.print_exc()
Ejemplo n.º 7
0
def main():
    cput, cget = make_channel()

    def ping():
        for i in range(20):
            cput(i)
            yield ready

    def pong():
        while True:
            print (yield call(whee))

    def whee(answer):
        x = yield cget
        y = yield cget
        answer(x + y)

    spawn(pong())
    spawn(ping())
    run()
Ejemplo n.º 8
0
def main():
    cput, cget = make_channel()

    def ping():
        for i in range(20):
            cput(i)
            yield ready

    def pong():
        while True:
            print(yield call(whee))

    def whee(answer):
        x = yield cget
        y = yield cget
        answer(x + y)

    spawn(pong())
    spawn(ping())
    run()
Ejemplo n.º 9
0
 def threadproc(arg):
     global sock1, pending, active
     def execute(s):
         if isinstance(s, p2p.ServerSocket):
             n = NetworkStub(Ks=crypto.generateRSA()[0], cert=None, model=model, view=control.view)
             s.start(net=n)
             node = model.addNode(s.net.node.guid, s)
             s.net.node.index = node.index # so that dht.Node has the index.
             active.append(s)
         else:
             if _debug: print s[0], s[1]
             result = yield s[0](**s[1])
             if not isinstance(result, list):
                 print result
             else:
                 if _debug: print result
                 values = map(lambda x: x[0], result)
                 print '\n'.join(values) if values else 'None'
     def waitonsock(sock):
         global pending
         try:
             while True: 
                 yield multitask.recvfrom(sock, 10)
                 for s in pending:
                     multitask.add(execute(s))
                 pending[:] = []
         except StopIteration:
             raise
         except:
             print 'waitonsock', sys.exc_info(), traceback.print_exc()
     multitask.add(waitonsock(sock1)) # this will trigger multitask out of wait loop
      
     if _debug: print 'starting multitask.run()'
     if _trace: sys.settrace(traceit)
     try: multitask.run()
     except KeyboardInterrupt: interrupt_main()
     except: 
         if _debug: print 'exception in multitask.run()'; traceback.print_exc()
Ejemplo n.º 10
0
def echo_server(hostname, port):
	addrinfo = socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
	(family, socktype, proto, canoname, sockaddr) = addrinfo[0]
	with closing(socket.socket(family, socktype, proto)) as sock:
		sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
		sock.bind(sockaddr)
		sock.listen(5)
		while True:
			multitask.add(client_handler(yield multitask.accept(sock))[0])

	if __name__ == '__main__':
		import sys
		hostname = None
		port = 1111
		if len(sys.argv) > 1:
			hostname = sys.argv[1]
		if len(sys.argv) > 2:
			port = int(sys.argv[2])
		multitask.add(echo_server(hostname, port))
		try:
			multitask.run()
		except KeyboardInterrupt:
			pass
Ejemplo n.º 11
0
        for x in filter(lambda x: x.tag == 'filled', items):
            pass # TODO: more
        
#------------------------------------------------------------------------------
# TESTING        
#------------------------------------------------------------------------------

def _testInterpret():
    try:
        yield interpret('example/goodbye1.vxml') # initial example
        yield interpret('example/goodbye2.vxml') # initial example
        yield interpret('example/leaf.vxml')     # multi-document
        yield interpret('example/app.vxml')      # subdialog
    
    except StopIteration: pass
    except Exception, e:
        print 'exception', type(e), e, traceback.print_exc()
    yield

def _testClose(): yield multitask.sleep(2); exit()

if __name__ == '__main__':
    import doctest; doctest.testmod()    # first run doctest,
    for f in dir():      # then run all _test* functions
        if str(f).find('_test') == 0 and callable(eval(f)):
            multitask.add(globals()[f]())
    try: multitask.run()
    except KeyboardInterrupt: pass
    except select.error: print 'select error'; pass
    sys.exit()
Ejemplo n.º 12
0
def run():
    '''The run loop which runs the multitask's main loop. This can be terminated by KeyboardInterrupt.'''
    try:
        multitask.run()
    except KeyboardInterrupt:
        pass
Ejemplo n.º 13
0
def run():
    '''The run loop which runs the multitask's main loop. This can be terminated by KeyboardInterrupt.'''
    try: multitask.run()
    except KeyboardInterrupt: pass
Ejemplo n.º 14
0
    yield multitask.sleep(1)
    u1.roster.presence = Presence(show='dnd', status='Online')

    h1 = u1.chat('*****@*****.**')
    yield h1.send(Message(body='Hello How are you?'))

    count = 5
    for i in xrange(5):
        try:
            msg = yield h1.recv(timeout=120)
            print msg
            print '%s: %s'%(msg.frm, msg.body.cdata)
            yield h1.send(Message(body='You said "%s"'%(msg.body.cdata)))
        except Exception, e:
            print str(type(e)), e
            break
        
    yield u1.logout()
    print 'testPresence exiting'

def testClose(): yield multitask.sleep(25); exit()

if __name__ == '__main__':
    import doctest; doctest.testmod()    # first run doctest,
    for f in dir():      # then run all _test* functions
        if str(f).find('_test') == 0 and callable(eval(f)):
            multitask.add(globals()[f]())
    try: multitask.run()
    except KeyboardInterrupt: pass
    except select.error: print 'select error'; pass
    sys.exit()
Ejemplo n.º 15
0
def speed_test_1():
    t_start = time.time()
    multitask.add(coroutine_1())
    multitask.add(coroutine_2())
    multitask.run()
    print('sp1: {0} [ms]'.format((time.time() - t_start)*1000))
Ejemplo n.º 16
0
def run_crawler(config_file):
    with open(config_file) as fd:
        config_all = json.load(fd)
        run(config_all['indexes'])
Ejemplo n.º 17
0
              pass			
            p = None
          log.info('incoming call cancelled')	  
          break
    elif cmd == 'close':
      log.info('incoming call cancelled by %s', arg)
    elif cmd == 'send':
      log.info('paging-mode IM received %s', arg)	


if __name__ == '__main__':
  try:
    argv = sys.argv
    i, username, password, media = 1, None, None, None
    while i < len(argv):
      if argv[i] == '-u':
        if username:		
          multitask.add(register(username, password, media))
          username, password, media = None, None, None		
        username = argv[i+1]
      elif argv[i] == '-p':
        password = argv[i+1]
      elif argv[i] == '-m':
        media = argv[i+1]
      i += 2		
    multitask.add(register(username, password, media))
    multitask.run()
  except KeyboardInterrupt:
    pass

    
Ejemplo n.º 18
0
# Mail: [email protected]  @@  [email protected]
# Created Time: Fri Mar 29 13:04:42 2019
# Description:
#************************************************************************#

import multitask
import time


def coroutine_1():
    for i in range(3):
        print 'c1'
        yield i


def coroutine_2():
    for i in range(3):
        print 'c2'
        yield i


print '-------------------------------------'
print multitask.add(coroutine_1())

print '-------------------------------------'

print multitask.add(coroutine_2())
print '-------------------------------------'
print multitask.run()
print '-------------------------------------'
Ejemplo n.º 19
0
    except KeyboardInterrupt:
        result = (True, 'Keyboard Interrupt')
    yield s.close()
    yield d.close()
    raise Result, result


#--------------------------------
# Module's main
#--------------------------------

_usage = '''usage: python rtmpclient.py [-d] src dest
  -d: verbose mode prints trace statements
  src and dest: either "rtmp" URL or a file name. Use "id" to specify stream name, e.g., rtmp://localhost/myapp?id=user1
  This software depends on Python 2.6 (won't work with 2.4 or 3.0)'''

# The main routine to invoke the copy method
if __name__ == '__main__':
    if len(sys.argv) < 3:
        print _usage
        sys.exit(-1)
    _debug = sys.argv[1] == '-d'

    try:
        multitask.add(copy(sys.argv[-2], sys.argv[-1]))
        multitask.run()
    except Result, e:
        print 'result', e
    except KeyboardInterrupt:
        if _debug: print 'keyboard interrupt'
Ejemplo n.º 20
0
def speed_test_1():
    t_start = time.time()
    multitask.add(coroutine_1())
    multitask.add(coroutine_2())
    multitask.run()
    print('sp1: {0} [ms]'.format((time.time() - t_start) * 1000))