python-astrodynamics / spacetrack

Python client for space-track.org
MIT License
74 stars 15 forks source link

Runtime Error on Fresh install #38

Closed skulumani closed 7 years ago

skulumani commented 7 years ago

Hello I'm recieving a runtime error while trying to run through the examples.

Any suggestions on how to fix it?

Thank you

---------------------------------------------------------------------------                    
RuntimeError                              Traceback (most recent call last)                    
<ipython-input-3-661127812ad6> in <module>()   
----> 1 st = SpaceTrackClient(identity='email', password='passowrd')  

/home/shankar/anaconda3/lib/python3.6/site-packages/spacetrack/base.py in __init__(self, identity, password)                                                                                  
    166         # your query frequency to less than 20 requests per minute."                   
    167         self._ratelimiter = RateLimiter(                                               
--> 168             max_calls=19, period=60, callback=self._ratelimit_callback)                
    169                                        
    170     def _ratelimit_callback(self, until):                                              

/home/shankar/anaconda3/lib/python3.6/site-packages/ratelimiter.py in __init__(self, max_calls, period, callback)                                                                             
     53         if PY35:                       
     54             import asyncio             
---> 55             self._alock = asyncio.Lock()                                               
     56                                        
     57     def __call__(self, f):             

/home/shankar/anaconda3/lib/python3.6/asyncio/locks.py in __init__(self, loop)                 
    147             self._loop = loop          
    148         else:                          
--> 149             self._loop = events.get_event_loop()                                       
    150                                        
    151     def __repr__(self):                

/home/shankar/anaconda3/lib/python3.6/asyncio/events.py in get_event_loop()                    
    669     if current_loop is not None:       
    670         return current_loop            
--> 671     return get_event_loop_policy().get_event_loop()                                    
    672                                        
    673                                        

/home/shankar/anaconda3/lib/python3.6/asyncio/events.py in get_event_loop(self)                
    581         if self._local._loop is None:  
    582             raise RuntimeError('There is no current event loop in thread %r.'          
--> 583                                % threading.current_thread().name)                      
    584         return self._local._loop       
    585                                        

RuntimeError: There is no current event loop in thread 'Dummy-31'. 
RazerM commented 7 years ago

Can you provide a short script that shows the problem (an MVCE)?

skulumani commented 7 years ago

Sure thing,

I'm using Anaconda and here is a list of installed packages.

These are the steps I'm using to try and test Spacetrack

ipython
from spacetrack import SpaceTrackClient
st = SpaceTrackClient(identity='email', password='password')

This will give the error shown above.

Am I missing a required package or other dependency?

RazerM commented 7 years ago

Thanks, I'm able to reproduce the bug on Anaconda 4.4.0.

RazerM commented 7 years ago

There's an asyncio.Lock() created by RateLimiter, which requires an event loop. Only the main thread has one by default and for some reason this happens on Anaconda 4.4.0:

import threading

print(threading.current_thread())
import spacetrack
print(threading.current_thread())
<_MainThread(MainThread, started 140737209025472)>
<_DummyThread(Dummy-1, started daemon 140737209025472)>

I don't understand why this is happening, but it does show that the ratelimiter module should not be creating an asyncio lock eagerly in case it is being used in a thread.

skulumani commented 7 years ago

Thank you for checking on it so quickly. I can try using a different version of Anaconda and see if the issue persists.

On Sat, Jun 17, 2017 at 1:39 PM, Frazer McLean notifications@github.com wrote:

There's an asyncio.Lock() created by RateLimiter, which requires an event loop. Only the main thread has one by default and for some reason this happens on Anaconda 4.4.0:

import threading

print(threading.current_thread()) import spacetrack print(threading.current_thread())

<_MainThread(MainThread, started 140737209025472)> <_DummyThread(Dummy-1, started daemon 140737209025472)>

I don't understand why this is happening, but it does show that the ratelimiter module should not be creating an asyncio lock eagerly in case it is being used in a thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/python-astrodynamics/spacetrack/issues/38#issuecomment-309229386, or mute the thread https://github.com/notifications/unsubscribe-auth/AFBaZt3SgPgimMxbjZeZv7gO1g4-ipU3ks5sFA9tgaJpZM4N9Rg9 .

RazerM commented 7 years ago

It doesn't happen on Anaconda 4.3.1

RazerM commented 7 years ago

You can pip install -U ratelimiter to get the fix. I will release a new spacetrack that requires ratelimiter>=1.2