Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- python << EOF
- import vim
- from random import randint
- from time import sleep
- from threading import Thread
- data = {
- 'produced': [],
- 'producer': None,
- 'stop': False
- }
- def produce():
- while not data['stop']:
- sleep(2)
- for i in xrange(1, 10):
- data['produced'].append(randint(0, i) * 5)
- vim.command("call defer('Consume')")
- sleep(2)
- EOF
- function Produce()
- python << EOF
- data['stop'] = False
- data['producer'] = Thread(target=produce)
- data['producer'].start()
- EOF
- endfunction
- function Consume()
- python << EOF
- vim.current.buffer.append('Generated by separate thread: -- %s --' % ', '.join(map(str, data['produced'])))
- data['produced'] = []
- EOF
- endfunction
- function Stop()
- python << EOF
- data['stop'] = True
- EOF
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement