twblue/src/mysc/thread_utils.py

33 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
import threading
import wx
2015-01-08 15:01:45 +01:00
from pubsub import pub
from twython import TwythonRateLimitError
import time
def call_threaded(func, *args, **kwargs):
#Call the given function in a daemonized thread and return the thread.
def new_func(*a, **k):
try:
func(*a, **k)
except TwythonRateLimitError:
wx.MessageDialog(None, u"Has superado el límite de llamadas a la API que Twitter permite. Eso puede deberse a muchas líneas temporales abiertas, a abrir y cerrar el programa en un periodo corto de tiempo, o a tener muchas llamadas a la API en tu configuración. TW Blue esperará 5 minutos y volverá a intentarlo.", u"Límite de llamadas a la API Superado", wx.ICON_ERROR|wx.OK).ShowModal()
time.sleep(300)
call_threaded(func, *args, **kwargs)
# except:
# pass
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
thread.daemon = True
thread.start()
return thread
2015-01-08 15:01:45 +01:00
def stream_threaded(func, *args, **kwargs):
def new_func(*a, **k):
try:
func(*a, **k)
except:
pub.sendMessage("streamError")
thread = threading.Thread(target=new_func, args=args, kwargs=kwargs)
thread.daemon = True
thread.start()
return thread