def listen(self):
		server = ModuleServer(self.options.module)

		# ensure that the UNIX socket is only accessable by root
		old_umask = umask(0077)
		try:
			reactor.listenUNIX(self.options.socket, server)
		finally:
			umask(old_umask)

		notifier.loop()
Esempio n. 2
0
import os, sys

#import twisted

import notifier

notifier.init( notifier.TWISTED )

def hello( *args ):
	print 'Hello World'

# notifier-timer testfunction
def timer_test():
	print "timer_test"
#	 notifier.dispatcher_add( notifier.Callback( dispatcher_test, 1, 2, 3 ) )
	return True

def dispatcher_test( a, b, c ):
	print 'dispatcher', a, b, c
	return True

def _stdin( fd ):
	print 'read: ' + os.read( fd, 512 )
	notifier.socket_remove( 0 )
	return False

notifier.socket_add( 0, _stdin )
notifier.timer_add( 4000, notifier.Callback( timer_test ) )
notifier.dispatcher_add( notifier.Callback( dispatcher_test, 1, 2, 3 ) )
notifier.loop()
Esempio n. 3
0

@nfthreads.threaded(done_with_it)
def my_thread():
    number = random.randint(50, 100)
    for i in range(number):
        time.sleep(0.1)
    if random.randint(0, 10) < 6:
        raise Exception('mysterious problem')
    return number


def doing_something_else():
    print '>>> Pick me!'
    return True


if __name__ == '__main__':
    notifier.init(notifier.GENERIC)

    _stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
    _stdout.write('Starting threads ')
    for i in range(100):
        _stdout.write('.')
        my_thread()
        time.sleep(0.02)
        _stdout.write('\033[1D*')
    _stdout.write('\n')
    notifier.timer_add(1000, doing_something_else)
    notifier.loop()
Esempio n. 4
0
		self.setActiveWindow( self.dialog )

		self.button = qt.QPushButton( 'Hello World', self.dialog )
		self.dialog.show()
		qt.QObject.connect( self.button, qt.SIGNAL( 'clicked()' ), self.clickedButton )
		self.timer_id = notifier.timer_add( 1000, self.timerTest )
		self.dispatch_it = 10

	def recvQuit( self, mmsg, data = None ):
		self.quit()

	def clickedButton( self ):
		print "bye"
		self.quit( 1 )

	def timerTest( self ):
		print 'tick'
		return True

	def _dispatch( self ):
		print 'dispatch'
		self.dispatch_it -= 1
		return self.dispatch_it > 0

if __name__ == '__main__':
	notifier.init( notifier.QT )
	app = QTestApp()

	notifier.dispatcher_add( app._dispatch )
	print 'exit code: %d' % notifier.loop()
Esempio n. 5
0
	def run( self ):
		self._timer = notifier.timer_add( 2000, self.tick )

		notifier.loop()
Esempio n. 6
0
    def run(self):
        self._timer = notifier.timer_add(2000, self.tick)

        notifier.loop()