Repository: praw-dev/praw

Issue:
When run on a single secondary thread, reddit._check_for_async() throws an exception
**Describe the bug**
When run on a thread other than the main thread, updating a wiki page throws an exception when calling "_check_for_async()". As per the [Release Notes](https://praw.readthedocs.io/en/latest/package_info/change_log.html), 7.1.2 claims that `Fixed: Asynchronous check would not work on Python 3.6 as asyncio.get_running_loop only exists on Python 3.7+.` - this seems to apply here as I'm using [python 3.6.8 with PRAW 7.1.3](https://i.redd.it/bsmyb96qt3g61.png). So does this indicate that that issue was perhaps not fully fixed?

**To Reproduce**
Steps to reproduce the behavior:

```
from threading import Thread

def update_wiki():
   r = praw.Reddit("username")
   subreddit = r.subreddit("name")
   table = "Some string"
   subreddit.wiki["name"].edit(table)

## WORKS: ##
update_wiki()

## FAILS: ##
Thread(target=update_wiki).start()

```

**Expected behavior**
No exception thrown

**Stack Trace**
```Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python36\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\James\source\repos\RoboKaywee\RoboKaywee\RoboKaywee.py", line 245, in update_commands_wiki
    subreddit.wiki["commands"].edit(table)
  File "C:\Program Files\Python36\lib\site-packages\praw\models\reddit\wikipage.py", line 232, in edit
    data=other_settings,
  File "C:\Program Files\Python36\lib\site-packages\praw\reddit.py", line 719, in post
    path=path,
  File "C:\Program Files\Python36\lib\site-packages\praw\reddit.py", line 633, in _objectify_request
    path=path,
  File "C:\Program Files\Python36\lib\site-packages\praw\reddit.py", line 805, in request
    self._check_for_async()
  File "C:\Program Files\Python36\lib\site-packages\praw\reddit.py", line 385, in _check_for_async
    in_async = asyncio.get_event_loop().is_running()
  File "C:\Program Files\Python36\lib\asyncio\events.py", line 694, in get_event_loop
    return get_event_loop_policy().get_event_loop()
  File "C:\Program Files\Python36\lib\asyncio\events.py", line 602, in get_event_loop
    % threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-1'.

```

**System Info**
 - OS: Windows 10
 - Python: 3.6.8
 - PRAW Version: 7.1.3

-----

This call to subreddit.wiki.edit() succeeded in a previous version of PRAW, but since a recent update (7.1.1 maybe? I've updated twice in the last week when prompted to) it now raises this exception. Running this on the main thread only works fine.

I know that [PRAW is not necessarily thread safe](https://praw.readthedocs.io/en/latest/getting_started/multiple_instances.html#:~:text=Multiple%20Threads,-Warning&text=PRAW%20is%20not%20thread%20safe.), HOWEVER in my code PRAW is only ever running on a single thread.. There is never a time when two threads try to use PRAW at the same time. As per the [linked github issue](https://github.com/psf/requests/issues/2766), `Session is not threadsafe. If you are using requests with an explicit Session object in a multithreaded program, you should create one Session per thread`. As I'm using PRAW on a single thread only, this should mean PRAW works fine. And again, it did until recently (error first noticed within the last week or so).


The full details of my code are here if needed: 

* The thread is spawned (from the main thread) here: https://github.com/theonefoster/RoboKaywee/blob/master/RoboKaywee.py#L247

* The PRAW call which raises the exception:  https://github.com/theonefoster/RoboKaywee/blob/master/RoboKaywee.py#L234


Discussion:
Interesting use case. I was able to reproduce this and will get it fixed soon. 

Thanks for reporting this!

Resolving patch:
diff --git a/praw/reddit.py b/praw/reddit.py
--- a/praw/reddit.py
+++ b/praw/reddit.py
@@ -375,14 +375,14 @@ def _check_for_async(self):
             except NameError:
                 pass
             in_async = False
-            if sys.version_info >= (3, 7, 0):
-                try:
+            try:
+                if sys.version_info >= (3, 7, 0):
                     asyncio.get_running_loop()
                     in_async = True
-                except RuntimeError:
-                    pass
-            else:
-                in_async = asyncio.get_event_loop().is_running()
+                else:
+                    in_async = asyncio.get_event_loop().is_running()
+            except Exception:  # Quietly fail if any exception occurs during the check
+                pass
             if in_async:
                 logger.warning(
                     "It appears that you are using PRAW in an asynchronous"


Test patch: