forked from rDrama/rDrama
use gevent.with_timeout whenever u can
parent
a78157208e
commit
eb0af76e46
|
@ -37,13 +37,13 @@ def _archiveorg(url):
|
||||||
|
|
||||||
|
|
||||||
def archive_url(url):
|
def archive_url(url):
|
||||||
gevent.spawn(_archiveorg, url)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _archiveorg, url)
|
||||||
if url.startswith('https://twitter.com/'):
|
if url.startswith('https://twitter.com/'):
|
||||||
url = url.replace('https://twitter.com/', 'https://nitter.net/')
|
url = url.replace('https://twitter.com/', 'https://nitter.net/')
|
||||||
gevent.spawn(_archiveorg, url)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _archiveorg, url)
|
||||||
if url.startswith('https://instagram.com/'):
|
if url.startswith('https://instagram.com/'):
|
||||||
url = url.replace('https://instagram.com/', 'https://imginn.com/')
|
url = url.replace('https://instagram.com/', 'https://imginn.com/')
|
||||||
gevent.spawn(_archiveorg, url)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _archiveorg, url)
|
||||||
|
|
||||||
def snappy_report(post, reason):
|
def snappy_report(post, reason):
|
||||||
report = Report(post_id=post.id, user_id=SNAPPY_ID, reason=reason)
|
report = Report(post_id=post.id, user_id=SNAPPY_ID, reason=reason)
|
||||||
|
|
|
@ -239,7 +239,7 @@ def push_notif(uids, title, body, url_or_comment):
|
||||||
|
|
||||||
subscriptions = g.db.query(PushSubscription.subscription_json).filter(PushSubscription.user_id.in_(uids)).all()
|
subscriptions = g.db.query(PushSubscription.subscription_json).filter(PushSubscription.user_id.in_(uids)).all()
|
||||||
subscriptions = [x[0] for x in subscriptions]
|
subscriptions = [x[0] for x in subscriptions]
|
||||||
gevent.spawn(_push_notif_thread, subscriptions, title, body, url)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _push_notif_thread, subscriptions, title, body, url)
|
||||||
|
|
||||||
|
|
||||||
def _push_notif_thread(subscriptions, title, body, url):
|
def _push_notif_thread(subscriptions, title, body, url):
|
||||||
|
|
|
@ -1157,3 +1157,5 @@ from sqlalchemy.orm import scoped_session, sessionmaker
|
||||||
|
|
||||||
engine = create_engine(environ.get("DATABASE_URL").strip(), connect_args={"options": "-c statement_timeout=5000 -c idle_in_transaction_session_timeout=40000"})
|
engine = create_engine(environ.get("DATABASE_URL").strip(), connect_args={"options": "-c statement_timeout=5000 -c idle_in_transaction_session_timeout=40000"})
|
||||||
db_session = scoped_session(sessionmaker(bind=engine, autoflush=False))
|
db_session = scoped_session(sessionmaker(bind=engine, autoflush=False))
|
||||||
|
|
||||||
|
GEVENT_GENERIC_TIMEOUT = 10
|
||||||
|
|
|
@ -150,7 +150,7 @@ def process_video(file, v):
|
||||||
if extension != '.mp4':
|
if extension != '.mp4':
|
||||||
new = new.replace(extension, '.mp4')
|
new = new.replace(extension, '.mp4')
|
||||||
copyfile(old, new)
|
copyfile(old, new)
|
||||||
gevent.spawn(convert_to_mp4, old, new)
|
gevent.with_timeout(35, convert_to_mp4, old, new)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
subprocess_run(["ffmpeg", "-loglevel", "quiet", "-y", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new])
|
subprocess_run(["ffmpeg", "-loglevel", "quiet", "-y", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new])
|
||||||
|
|
|
@ -54,5 +54,5 @@ if FEATURES['PING_GROUPS']:
|
||||||
if IS_LOCALHOST:
|
if IS_LOCALHOST:
|
||||||
from files.helpers.cron import cron_fn
|
from files.helpers.cron import cron_fn
|
||||||
print('Starting cron tasks!', flush=True)
|
print('Starting cron tasks!', flush=True)
|
||||||
gevent.spawn(cron_fn, True, False)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, cron_fn, True, False)
|
||||||
print('Cron tasks Finished!', flush=True)
|
print('Cron tasks Finished!', flush=True)
|
||||||
|
|
|
@ -57,7 +57,7 @@ def post_pid_comment_cid(cid, v, pid=None, anything=None, sub=None):
|
||||||
post = NOTIFICATION_THREAD
|
post = NOTIFICATION_THREAD
|
||||||
|
|
||||||
if v and request.values.get("read"):
|
if v and request.values.get("read"):
|
||||||
gevent.spawn(_mark_comment_as_read, comment.id, v.id)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _mark_comment_as_read, comment.id, v.id)
|
||||||
|
|
||||||
post = get_post(post, v=v)
|
post = get_post(post, v=v)
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ def post_id(pid, v, anything=None, sub=None):
|
||||||
if not g.is_api_or_xhr and p.over_18 and not (v and v.over_18) and session.get('over_18_cookies', 0) < int(time.time()):
|
if not g.is_api_or_xhr and p.over_18 and not (v and v.over_18) and session.get('over_18_cookies', 0) < int(time.time()):
|
||||||
return render_template("errors/nsfw.html", v=v)
|
return render_template("errors/nsfw.html", v=v)
|
||||||
|
|
||||||
gevent.spawn(_add_post_view, pid)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_post_view, pid)
|
||||||
|
|
||||||
if p.new: defaultsortingcomments = 'new'
|
if p.new: defaultsortingcomments = 'new'
|
||||||
elif v: defaultsortingcomments = v.defaultsortingcomments
|
elif v: defaultsortingcomments = v.defaultsortingcomments
|
||||||
|
@ -676,7 +676,7 @@ def submit_post(v, sub=None):
|
||||||
g.db.flush() #Necessary, do NOT remove
|
g.db.flush() #Necessary, do NOT remove
|
||||||
|
|
||||||
if not p.thumburl and p.url and p.domain != SITE:
|
if not p.thumburl and p.url and p.domain != SITE:
|
||||||
gevent.spawn(thumbnail_thread, p.url, p.id)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, thumbnail_thread, p.url, p.id)
|
||||||
|
|
||||||
if v.client: return p.json
|
if v.client: return p.json
|
||||||
else:
|
else:
|
||||||
|
@ -920,7 +920,6 @@ extensions = IMAGE_FORMATS + VIDEO_FORMATS + AUDIO_FORMATS
|
||||||
@limiter.limit("3/minute", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
@limiter.limit("3/minute", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
||||||
@auth_required
|
@auth_required
|
||||||
def get_post_title(v):
|
def get_post_title(v):
|
||||||
POST_TITLE_TIMEOUT = 5
|
|
||||||
url = request.values.get("url")
|
url = request.values.get("url")
|
||||||
if not url or '\\' in url: abort(400)
|
if not url or '\\' in url: abort(400)
|
||||||
url = url.strip()
|
url = url.strip()
|
||||||
|
@ -931,7 +930,7 @@ def get_post_title(v):
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
x = gevent.with_timeout(POST_TITLE_TIMEOUT, requests.get, url, headers=HEADERS, timeout=POST_TITLE_TIMEOUT, proxies=proxies)
|
x = gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, requests.get, url, headers=HEADERS, proxies=proxies)
|
||||||
except: abort(400)
|
except: abort(400)
|
||||||
|
|
||||||
content_type = x.headers.get("Content-Type")
|
content_type = x.headers.get("Content-Type")
|
||||||
|
|
|
@ -877,7 +877,7 @@ def settings_song_change(v):
|
||||||
if duration > 15:
|
if duration > 15:
|
||||||
return redirect("/settings/personal?error=Duration of the video must not exceed 15 minutes!")
|
return redirect("/settings/personal?error=Duration of the video must not exceed 15 minutes!")
|
||||||
|
|
||||||
gevent.spawn(_change_song_youtube, v.id, id)
|
gevent.with_timeout(60, _change_song_youtube, v.id, id)
|
||||||
|
|
||||||
return redirect("/settings/personal?msg=Profile Anthem successfully updated. Wait 5 minutes for the change to take effect.")
|
return redirect("/settings/personal?msg=Profile Anthem successfully updated. Wait 5 minutes for the change to take effect.")
|
||||||
|
|
||||||
|
|
|
@ -951,7 +951,7 @@ def u_username_wall(v, username):
|
||||||
is_following = v and u.has_follower(v)
|
is_following = v and u.has_follower(v)
|
||||||
|
|
||||||
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
|
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
|
||||||
gevent.spawn(_add_profile_view, v.id, u.id)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id)
|
||||||
|
|
||||||
page = get_page()
|
page = get_page()
|
||||||
|
|
||||||
|
@ -998,10 +998,10 @@ def u_username_wall_comment(v, username, cid):
|
||||||
is_following = v and u.has_follower(v)
|
is_following = v and u.has_follower(v)
|
||||||
|
|
||||||
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
|
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
|
||||||
gevent.spawn(_add_profile_view, v.id, u.id)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id)
|
||||||
|
|
||||||
if v and request.values.get("read"):
|
if v and request.values.get("read"):
|
||||||
gevent.spawn(_mark_comment_as_read, comment.id, v.id)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _mark_comment_as_read, comment.id, v.id)
|
||||||
|
|
||||||
try: context = min(int(request.values.get("context", 8)), 8)
|
try: context = min(int(request.values.get("context", 8)), 8)
|
||||||
except: context = 8
|
except: context = 8
|
||||||
|
@ -1043,7 +1043,7 @@ def u_username(v, username):
|
||||||
return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403
|
return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403
|
||||||
|
|
||||||
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
|
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
|
||||||
gevent.spawn(_add_profile_view, v.id, u.id)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id)
|
||||||
|
|
||||||
sort = request.values.get("sort", "new")
|
sort = request.values.get("sort", "new")
|
||||||
t = request.values.get("t", "all")
|
t = request.values.get("t", "all")
|
||||||
|
@ -1110,7 +1110,7 @@ def u_username_comments(username, v):
|
||||||
return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403
|
return render_template("userpage/private.html", u=u, v=v, is_following=is_following), 403
|
||||||
|
|
||||||
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
|
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
|
||||||
gevent.spawn(_add_profile_view, v.id, u.id)
|
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id)
|
||||||
|
|
||||||
page = get_page()
|
page = get_page()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue