ConnectedPapers / connectedpapers-py

MIT License
20 stars 2 forks source link

RuntimeError('Event loop is closed') on running the sample code on test paper #1

Closed Ghost---Shadow closed 11 months ago

Ghost---Shadow commented 11 months ago

Here is the code

from connectedpapers import ConnectedPapersClient

DEEPFRUITS_PAPER_ID = "9397e7acd062245d37350f5c05faf56e9cfae0d6"

# TEST_TOKEN allows access ONLY to the paper with the id DEEPFRUITS_PAPER_ID
client = ConnectedPapersClient(access_token="TEST_TOKEN")
remaining_uses_count = client.get_remaining_usages_sync()
print(f"Remaining uses count: {remaining_uses_count}")
free_access_papers = client.get_free_access_papers_sync()
print(f"Free access papers: {free_access_papers}")
graph = client.get_graph_sync(DEEPFRUITS_PAPER_ID)
assert graph.graph_json.start_id == DEEPFRUITS_PAPER_ID

Here is my trace

python connected_papers_demo.py
Remaining uses count: 0
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F965B22E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F965B22E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Free access papers: ['9397e7acd062245d37350f5c05faf56e9cfae0d6']
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F965B22E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F965B22E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F965B22E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
(base) PS C:\Users\windows\Desktop\mass-pdf-chatgpt> python connected_papers_demo.py
Remaining uses count: 0
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F1A1713E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Free access papers: ['9397e7acd062245d37350f5c05faf56e9cfae0d6']
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F1A1713E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F1A1713E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F1A1713E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F1A1713E50>
Traceback (most recent call last):
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\windows\miniconda3\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\windows\miniconda3\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Here is my python

Python 3.8.15 (default, Nov 24 2022, 14:38:14) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Ghost---Shadow commented 11 months ago

Using my early access token gives the same problem

KanHarI commented 11 months ago

Hi, I will find a windows anaconda setup to test on and try to reproduce. Does this error reproduces outside of Anaconda? Can you try maybe creating a venv, installing the PyPi package and testing there?

Ghost---Shadow commented 11 months ago

Changing the sync functions to this fixes it. Thanks GPT4

import nest_asyncio
...
class ConnectedPapersClient:
    ...
    def get_free_access_papers_sync(self) -> List[PaperID]:
        nest_asyncio.apply()
        return asyncio.run(self.get_free_access_papers_async())
KanHarI commented 11 months ago

Deploying a fix in a few minutes, thanks

KanHarI commented 11 months ago

Fixed in https://github.com/ConnectedPapers/connectedpapers-py/pull/3

KanHarI commented 11 months ago

Fix deployed. Please comment here if the issue persists for anyone with the latest version

KanHarI commented 11 months ago

(Assuming this is fixed, please open a new issue if anyone encounters this again)

Ghost---Shadow commented 11 months ago

I still see the old code after pip installing. Did it deploy correctly?