Instapy: new LOGGER with schdule, second job will print the same line twice

Created on 26 Nov 2017  路  13Comments  路  Source: timgrossmann/InstaPy

the third job will print the same line 3 times.
e.g.
INFO - [1/195]
INFO - [1/195]
INFO - https://www.instagram.com/p/Bb8md8RjY0T/?tagged=babygirl
INFO - https://www.instagram.com/p/Bb8md8RjY0T/?tagged=babygirl
INFO - Image from: b'blondeswhoblog'
INFO - Image from: b'blondeswhoblog'
INFO - Number of Followers: 3988
INFO - Number of Followers: 3988

What should I do?

help wanted question wontfix

All 13 comments

Maybe object seesion need to be removed in exception ?

It's because InstaPy is single thread, if you run InstaPy more than once, log file will save all the calls in the same file.

I don't run it threaded, the schduler run serial, no?
It is the same log file printed, not 2 diffrent.

Can you enlight me ?

We initialize the handler more than once, so solution is to update or to check that it is not already initialized.

It is a bug... will it be fixed ? or should I read about LOGGER and fix it myself :)

@sionking Best option is always the last one :wink:

The correct use of logger is to initialize it once as global, so it can be used over all instances, it is a good way to go when we will move to threaded.

need to add 2 lines:
file_handler.setFormatter(logger_formatter) if (self.logger.hasHandlers()): self.logger.handlers.clear() self.logger.addHandler(file_handler)

If we already have handler than clear it before adding new one.

@sionking that solution isn't working for me:
'Logger' object has no attribute 'hasHandlers'

@sionking this working foto me
+1

_clear()_ method only work in Python3.
Solved with:

if self.logger.handlers:
            del self.logger.handlers[:]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this problem still occurs, please open a new issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harrypython picture harrypython  路  3Comments

CodeMaster1 picture CodeMaster1  路  3Comments

seuraltimez picture seuraltimez  路  3Comments

n0sw34r picture n0sw34r  路  3Comments

tibor picture tibor  路  3Comments