scrapely-python 0.1.24__py3-none-any.whl → 0.1.25__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
scrapely/__init__.py CHANGED
@@ -227,7 +227,7 @@ if TYPE_CHECKING: # Static analysers and IDEs see the lazy names as plain impor
227
227
  set_api_storage,
228
228
  )
229
229
 
230
- __version__ = '0.1.24'
230
+ __version__ = '0.1.25'
231
231
  __all__ = [
232
232
  # Core
233
233
  'Actor',
scrapely/actor.py CHANGED
@@ -360,6 +360,7 @@ class Actor(metaclass=_ActorMeta):
360
360
 
361
361
  @classmethod
362
362
  async def init(cls, options: Optional[InitOptions] = None) -> None:
363
+ cls._main_loop = asyncio.get_running_loop() # for debug_capture_sync from worker threads
363
364
  if cls._initialized:
364
365
  return
365
366
 
@@ -934,6 +935,29 @@ class Actor(metaclass=_ActorMeta):
934
935
  import hashlib
935
936
  return 'DEBUG_CAPTURE_' + hashlib.sha1(str(key).strip().encode('utf-8')).hexdigest()[:24]
936
937
 
938
+ _main_loop: Optional[asyncio.AbstractEventLoop] = None
939
+
940
+ @classmethod
941
+ def debug_capture_sync(cls, key: str, payload: Any) -> None:
942
+ """debug_capture for synchronous code (also from worker threads, e.g. asyncio.to_thread).
943
+ Does nothing unless the platform enabled capture for this run."""
944
+ if os.environ.get('SCRAPELY_DEBUG_CAPTURE') != '1' or not key:
945
+ return
946
+ loop = cls._main_loop
947
+ if loop is None or loop.is_closed():
948
+ return
949
+ try:
950
+ try:
951
+ running = asyncio.get_running_loop()
952
+ except RuntimeError:
953
+ running = None
954
+ if running is loop:
955
+ loop.create_task(cls.debug_capture(key, payload))
956
+ else:
957
+ asyncio.run_coroutine_threadsafe(cls.debug_capture(key, payload), loop).result(timeout=15)
958
+ except Exception as err: # never break the run
959
+ logging.getLogger('scrapely').debug('debug_capture_sync failed: %s', err)
960
+
937
961
  @classmethod
938
962
  async def debug_capture(cls, key: str, payload: Any) -> None:
939
963
  """Save the raw source payload (API JSON or HTML) an item was extracted from, keyed by
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scrapely-python
3
- Version: 0.1.24
3
+ Version: 0.1.25
4
4
  Summary: Scrapely Python SDK - A toolkit for building Actors on the Scrapely platform
5
5
  Author-email: Scrapely <support@scrape.ly>
6
6
  License-Expression: MIT AND Apache-2.0
@@ -1,6 +1,6 @@
1
- scrapely/__init__.py,sha256=LwOxrcG5TcZ24X2RRNQl45zIwZY3UfvuIfHCRmWjuf4,9661
1
+ scrapely/__init__.py,sha256=2-L8VbKFypsPs_hl-GqCOKYwQvVcifUL4iXm0fOqhP4,9661
2
2
  scrapely/_browser_locations.py,sha256=8QVVnkms2bDn3_LDYgYDR59MvFx8757l_JYnZ7xb3oI,145269
3
- scrapely/actor.py,sha256=l-GDt7mqARs1RUk9u_HBVxj7TWcgRGCUKVqLduSstkw,86895
3
+ scrapely/actor.py,sha256=1SBHZYBRLmU4k_erjKL7yRfP0EgR7ZKXefAK8wWKRz0,88004
4
4
  scrapely/browser_configuration.py,sha256=jAZapNSHLFW05B96df4wNBtcyiiU9DA3ml0yTL1FwfA,5770
5
5
  scrapely/cdp_retry.py,sha256=hdTJEAIKhApM7IOk1DrQEl8NoflSJSmqd4RbNJ2IsgI,8540
6
6
  scrapely/charging.py,sha256=ns-kuUJtl8hBI4-3iBisC62BggJG67yYOa1yVVItoUI,83800
@@ -39,10 +39,10 @@ scrapely/storage/_file_system/_key_value_store_client.py,sha256=4Ipgbh4qEqAkwQJ9
39
39
  scrapely/storage/_file_system/_storage_client.py,sha256=aaGJ4P0QAtIgEMl6yHpuobeWFD5M4rMC5HwhOOvuGuo,1794
40
40
  scrapely/storage_clients/__init__.py,sha256=cs1YX7JV2_GKBXeiiJgkQFali08b5_y_jH6Yw7iROAA,656
41
41
  scrapely/storages/__init__.py,sha256=4PAELhJNZ3exJ7Uouicn-bCQ58NafKjhLBixQ8ATQc4,173
42
- scrapely_python-0.1.24.dist-info/licenses/LICENSE,sha256=pQGY0XwjIYh-a2HfawxHq1en53bXkFkDj2Q70jKWHr4,1088
43
- scrapely_python-0.1.24.dist-info/licenses/LICENSE-APACHE,sha256=N8m0FzMq8i4UbTgXZvKEZJSD-27OF8pWZYS_atz4kTU,11355
44
- scrapely_python-0.1.24.dist-info/licenses/NOTICE,sha256=DEsNrw6UdSIqdYYqMWVFgJnyt6jUivTD7iFU6YM_e1A,1122
45
- scrapely_python-0.1.24.dist-info/METADATA,sha256=YghofuDx8qPhqglQgjX-OD0tS5LXhskO5xNaV6BDHlg,3487
46
- scrapely_python-0.1.24.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
47
- scrapely_python-0.1.24.dist-info/top_level.txt,sha256=T4B9UMrs4q99QSAFyD1zdXhl40KnLhBKqrDkPhOTsmY,9
48
- scrapely_python-0.1.24.dist-info/RECORD,,
42
+ scrapely_python-0.1.25.dist-info/licenses/LICENSE,sha256=pQGY0XwjIYh-a2HfawxHq1en53bXkFkDj2Q70jKWHr4,1088
43
+ scrapely_python-0.1.25.dist-info/licenses/LICENSE-APACHE,sha256=N8m0FzMq8i4UbTgXZvKEZJSD-27OF8pWZYS_atz4kTU,11355
44
+ scrapely_python-0.1.25.dist-info/licenses/NOTICE,sha256=DEsNrw6UdSIqdYYqMWVFgJnyt6jUivTD7iFU6YM_e1A,1122
45
+ scrapely_python-0.1.25.dist-info/METADATA,sha256=9aB0qUPYZPSoRBuYQUIWWFQRnLrxpG66yP_ES6q_ZG8,3487
46
+ scrapely_python-0.1.25.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
47
+ scrapely_python-0.1.25.dist-info/top_level.txt,sha256=T4B9UMrs4q99QSAFyD1zdXhl40KnLhBKqrDkPhOTsmY,9
48
+ scrapely_python-0.1.25.dist-info/RECORD,,