Revert "use gevent.with_timeout whenever u can"

This reverts commit eb0af76e46.
pull/195/head
Aevann 2023-08-20 19:24:26 +03:00
parent 8b82ef35a8
commit e1d6c97465
9 changed files with 17 additions and 18 deletions

View File

@ -37,13 +37,13 @@ def _archiveorg(url):
def archive_url(url):
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _archiveorg, url)
gevent.spawn(_archiveorg, url)
if url.startswith('https://twitter.com/'):
url = url.replace('https://twitter.com/', 'https://nitter.net/')
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _archiveorg, url)
gevent.spawn(_archiveorg, url)
if url.startswith('https://instagram.com/'):
url = url.replace('https://instagram.com/', 'https://imginn.com/')
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _archiveorg, url)
gevent.spawn(_archiveorg, url)
def snappy_report(post, reason):
report = Report(post_id=post.id, user_id=SNAPPY_ID, reason=reason)

View File

@ -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 = [x[0] for x in subscriptions]
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _push_notif_thread, subscriptions, title, body, url)
gevent.spawn(_push_notif_thread, subscriptions, title, body, url)
def _push_notif_thread(subscriptions, title, body, url):

View File

@ -1157,5 +1157,3 @@ 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"})
db_session = scoped_session(sessionmaker(bind=engine, autoflush=False))
GEVENT_GENERIC_TIMEOUT = 10

View File

@ -150,7 +150,7 @@ def process_video(file, v):
if extension != '.mp4':
new = new.replace(extension, '.mp4')
copyfile(old, new)
gevent.with_timeout(35, convert_to_mp4, old, new)
gevent.spawn(convert_to_mp4, old, new)
else:
try:
subprocess_run(["ffmpeg", "-loglevel", "quiet", "-y", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new])

View File

@ -54,5 +54,5 @@ if FEATURES['PING_GROUPS']:
if IS_LOCALHOST:
from files.helpers.cron import cron_fn
print('Starting cron tasks!', flush=True)
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, cron_fn, True, False)
gevent.spawn(cron_fn, True, False)
print('Cron tasks Finished!', flush=True)

View File

@ -57,7 +57,7 @@ def post_pid_comment_cid(cid, v, pid=None, anything=None, sub=None):
post = NOTIFICATION_THREAD
if v and request.values.get("read"):
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _mark_comment_as_read, comment.id, v.id)
gevent.spawn(_mark_comment_as_read, comment.id, v.id)
post = get_post(post, v=v)

View File

@ -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()):
return render_template("errors/nsfw.html", v=v)
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_post_view, pid)
gevent.spawn(_add_post_view, pid)
if p.new: defaultsortingcomments = 'new'
elif v: defaultsortingcomments = v.defaultsortingcomments
@ -676,7 +676,7 @@ def submit_post(v, sub=None):
g.db.flush() #Necessary, do NOT remove
if not p.thumburl and p.url and p.domain != SITE:
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, thumbnail_thread, p.url, p.id)
gevent.spawn(thumbnail_thread, p.url, p.id)
if v.client: return p.json
else:
@ -920,6 +920,7 @@ extensions = IMAGE_FORMATS + VIDEO_FORMATS + AUDIO_FORMATS
@limiter.limit("3/minute", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def get_post_title(v):
POST_TITLE_TIMEOUT = 5
url = request.values.get("url")
if not url or '\\' in url: abort(400)
url = url.strip()
@ -930,7 +931,7 @@ def get_post_title(v):
abort(400)
try:
x = gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, requests.get, url, headers=HEADERS, proxies=proxies)
x = gevent.with_timeout(POST_TITLE_TIMEOUT, requests.get, url, headers=HEADERS, timeout=POST_TITLE_TIMEOUT, proxies=proxies)
except: abort(400)
content_type = x.headers.get("Content-Type")

View File

@ -877,7 +877,7 @@ def settings_song_change(v):
if duration > 15:
return redirect("/settings/personal?error=Duration of the video must not exceed 15 minutes!")
gevent.with_timeout(60, _change_song_youtube, v.id, id)
gevent.spawn(_change_song_youtube, v.id, id)
return redirect("/settings/personal?msg=Profile Anthem successfully updated. Wait 5 minutes for the change to take effect.")

View File

@ -951,7 +951,7 @@ def u_username_wall(v, username):
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"):
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id)
gevent.spawn(_add_profile_view, v.id, u.id)
page = get_page()
@ -998,10 +998,10 @@ def u_username_wall_comment(v, username, cid):
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"):
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id)
gevent.spawn(_add_profile_view, v.id, u.id)
if v and request.values.get("read"):
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _mark_comment_as_read, comment.id, v.id)
gevent.spawn(_mark_comment_as_read, comment.id, v.id)
try: context = min(int(request.values.get("context", 8)), 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
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id)
gevent.spawn(_add_profile_view, v.id, u.id)
sort = request.values.get("sort", "new")
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
if v and v.id != u.id and not v.admin_level and not session.get("GLOBAL"):
gevent.with_timeout(GEVENT_GENERIC_TIMEOUT, _add_profile_view, v.id, u.id)
gevent.spawn(_add_profile_view, v.id, u.id)
page = get_page()