This repository has been archived on 2024-12-08. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-08/src/class_bgWorker.py

39 lines
827 B
Python
Raw Normal View History

2013-06-28 09:25:31 +02:00
#! /usr/bin/python
# -*- coding: utf-8 -*-
# cody by linker.lin@me.com
__author__ = 'linkerlin'
import threading
import Queue
import time
2013-06-28 09:36:34 +02:00
class bgWorker(threading.Thread):
2013-06-28 09:25:31 +02:00
def __init__(self):
threading.Thread.__init__(self)
self.q = Queue.Queue()
def post(self,job):
self.q.put(job)
def run(self):
while 1:
job=None
try:
job = self.q.get(block=True)
if job:
job()
except Exception as ex:
print "Error,job exception:",ex.message,type(ex)
time.sleep(0.05)
else:
#print "job: ", job, " done"
pass
finally:
time.sleep(0.05)
2013-06-28 09:36:34 +02:00
bgworker = bgWorker()
2013-06-28 09:25:31 +02:00
bgworker.setDaemon(True)
bgworker.start()