Open noragen opened 4 years ago
Hi @noragen, did I understand correctly in #157 that it works for you with Python 3.8 but not with 3.7.3 as above?
Hi @carljm, actually yes, BUT I've now updated my conda base from 2019.03 to 2019.10 and python 3.7.3 to 3.7.5 And what should I say: The problem still exists in 3.7.5 base environment. So. Then I made a new virtual environment and tried it in the dedicated virtual env again:
(base) C:\projects>conda create -n py375 python=3.7.5 monkeytype
(base) C:\projects>conda activate py375
(py375) C:\projects>monkeytype run myscript.py
(py375) C:\projects>monkeytype stub some.module
def add(a: int, b: int) -> int: ...
(py375) C:\projects>
Interesting. I'm going to try to figure out whats happening here...
The first thing what came to my eyes was following: It is not a quite good idea to use imports of the same filename like the one in the standard-library:
Stay tuned. More is going to follow.
Hi @carljm ,
It looks like, that the CallTracer just logs nothing for any reason...
class CallTraceStoreLogger(CallTraceLogger):
"""A CallTraceLogger that stores logged traces in a CallTraceStore."""
def __init__(self, store: CallTraceStore) -> None: # β IS CALLED.
self.store = store
self.traces: List[CallTrace] = []
def log(self, trace: CallTrace) -> None: # π₯ IS NOT CALLED!
if not trace.func.__module__ == '__main__':
self.traces.append(trace)
def flush(self) -> None: # β IS CALLED.
self.store.add(self.traces)
self.traces = []
After long trying around I get following: I tried a simple example, looked whether there is a problem to set the profiler. I just executed a simple example and it worked in both environments (base and py375)
import sys
def test(n):
j = 0
for i in range(n):
j = j + i
return n
def profiler(frame, event, arg):
print (event, frame.f_code.co_name, frame.f_lineno, "->", arg)
# profiler is activated on the next call, return, or exception
sys.setprofile(profiler)
# profile this function call
test(1)
# disable profiler
sys.setprofile(None)
# don't profile this call
test(2)
which gave me in both environements:
(py375) C:\projects>python test_profile.py
call test 3 -> None
return test 7 -> 1
c_call <module> 19 -> <built-in function setprofile>
(py375) C:\projects>
and
(base) C:\projects>python test_profile.py
call test 3 -> None
return test 7 -> 1
c_call <module> 19 -> <built-in function setprofile>
(base) C:\projects>
So, now is the question, what is the problem, in my base-environment? What is different then, what prevents it from normal execution? The CallTraceStoreLogger.log was not being called.
Maybe it is any ContextManager related weird stuff? Or anything else?
Maybe you have an idea?
Best regards!
Hi @noragen -- really not sure. I recommend you see if CallTracer.__call__
is being called; that's the profiler entry point. If not, then the problem is with installing the profiler. If so, maybe you can trace where things are going off the rails from there.
Hi @carljm , thanks for the hints! π My setup is following:
The monkeytype.sqlite3 is there, but seems to be empty. Pls see the attachment. monkeytype.zip
I'm very thankful, that there are so guys like you who responds so fast! Thank you very much in advance! π
If you need more information or when you could give some debug hints, I really would like to help.
Best regards!
Originally posted by @noragen in https://github.com/Instagram/MonkeyType/issues/157#issuecomment-564929257