CA
Crawlee & Apify•13mo ago
extended-salmon

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.
3 Replies
MEE6
MEE6•13mo ago
@Deepak Antony just advanced to level 1! Thanks for your contributions! 🎉
Mantisus
Mantisus•13mo ago
@Deepak Antony Hey just use it everywhere.
from apify import Actor

def my_function():
Actor.log.info()
from apify import Actor

def my_function():
Actor.log.info()
Think of it as a singleton After calling
async with Actor:
(some code)
async with Actor:
(some code)
In all imports you will refer to this particular Actor
extended-salmon
extended-salmonOP•12mo ago
This is what I was wondering. As I checked the instance id across different files, they were all the same. Thank you for confirming @Mantisus

Did you find this page helpful?