Apify and Crawlee Official Forum

Updated 7 months ago

Using the Actor instance across multiple files

Hi, how can i use the same actor instance across multiple functions defined in seperate files?

for example, if I define an Actor in the main.py file as:

async with Actor:
(some code)


How do i use Actor.log.info() in another function that is called from the main script?

Would appreciate any help in this.
A
M
D
3 comments
just advanced to level 1! Thanks for your contributions! πŸŽ‰
Hey

just use it everywhere.
Plain Text
from apify import Actor

def my_function():
  Actor.log.info()

Think of it as a singleton
After calling
Plain Text
async with Actor:
     (some code)

In all imports you will refer to this particular Actor
This is what I was wondering. As I checked the instance id across different files, they were all the same.
Thank you for confirming
Add a reply
Sign up and join the conversation on Discord