Skip to content

Using sync method "urlUpload()" #5

@olmax04

Description

@olmax04

Hello,
I ran into a problem using the urlUpload() method. It calls the urlUploadSync() method, but this creates a problem to run in a thread. How can I get around this? Here is an example of my code:

import os
import threading
from pixelbin import PixelbinConfig, PixelbinClient


def func():
    config = PixelbinConfig({
        'domain': "https://api.pixelbin.io",
        'apiSecret': f'{os.environ.get("PIXELBIN_TOKEN")}'
    })
    pixelbin: PixelbinClient = PixelbinClient(config=config)
    image_url = "<image_url>"
    image_name = image_url.split("/")[-1]
    task = pixelbin.assets.urlUpload(url=image_url, path="/", name=image_name)
    print(task)


if __name__ == "__main__":
    t = threading.Thread(target=func())
    t.start()

And i have problem:

Exception in thread Thread-1 (func):
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/Olmax04/Desktop/CRM-OBJECT-PARSER/grand-real-estate-test/test.py", line 16, in func
    task = pixelbin.assets.urlUpload(url=image_url, path="/", name=image_name)
  File "/Users/Olmax04/Desktop/CRM-OBJECT-PARSER/grand-real-estate/venv/lib/python3.10/site-packages/pixelbin/platform/PixelbinClient.py", line 277, in urlUpload
    return asyncio.get_event_loop().run_until_complete(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/events.py", line 656, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-1 (func)'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions